Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will calling finish() from an activity free up my memory space?

I have an activity which uses considerable amount of memory in my app. So whenever the user switches over from that activity to some other activity, I am trying to call finish() to stop that activity.

My question is, will calling finish() from that activity free up memory space or just finishes that activity without cleaning the memory used by that particular activity?

Any help is much appreciated..

like image 900
Andro Selva Avatar asked May 23 '11 04:05

Andro Selva


2 Answers

Please try this in your activity and check..

@Override
public void onDestroy() {
    super.onDestroy();
    Runtime.getRuntime().gc();      
}
like image 59
Rukmal Dias Avatar answered Nov 18 '22 17:11

Rukmal Dias


The activity you're calling the finish() method from is destroyed and all its resources are queued for garbage collection, because a reference to this activity becomes inaccessible. So, all memory that was used by this activity will be freed during next GC cycle.

like image 34
Michael Avatar answered Nov 18 '22 19:11

Michael