开发者

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..


Please try this in your activity and check..

@Override
public void onDestroy() {
    super.onDestroy();
    Runtime.getRuntime().gc();      
}


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.


Yes pixie, is correct about finish(), just for more info on calling finish in activity, removes that activity from stack. Which means from traversing from Activity 1 --> Activity 2 and calling activity 2, if finish() is called in activity 1, then activity 1 gets removed from stack.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜