Skip to content Skip to sidebar Skip to footer

How To Release Or Clear The Value Of Variable Or Object?

I have an application in which I have used some variables and I want to release or free the memory space used by them after using them or on application close. Is there any process

Solution 1:

As you can see on the Activity lifecycle graph when a new activity is started the old one is merely paused and all values are retained.

It is not destroyed if there's no immediate need for memory for the rest of the system.

I assume that edt is in the layout taken via findViewById and not created by hand (not apparent from the code). So if you want to clear value of that EditText when switching back to old activity you need to do it by hand either in onPause or onResume.

On application close these will be released by Java VM. Keep in mind that your app might not be killed immediately after you leave last activity.

Solution 2:

I had answered a nearly similar question here : Android proper clean up/disposing

Basically what you need to do is set objects to null so that the garbage collector can clear it up when it runs.

Post a Comment for "How To Release Or Clear The Value Of Variable Or Object?"