从活动中调用 finish() 会释放我的内存空间吗?
我的应用程序中有一项活动占用了大量内存。因此,每当用户从该活动切换到其他活动时,我都会尝试调用 finish() 来停止该活动。
我的问题是,从该活动调用 finish() 会释放内存空间还是只是完成该活动而不清理该特定活动使用的内存?
非常感谢任何帮助..
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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请在您的活动中尝试此操作并检查..
Please try this in your activity and check..
您调用
finish()
方法的 Activity 将被销毁,并且其所有资源都会排队等待垃圾回收,因为对此 Activity 的引用变得无法访问。因此,该活动使用的所有内存都将在下一个 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.是的,pixie,关于 finish() 的说法是正确的,只是为了了解有关在活动中调用 finish 的更多信息,从堆栈中删除该活动。这意味着从 Activity 1 开始遍历 -->活动 2 并调用活动 2,如果在活动 1 中调用 finish(),则活动 1 将从堆栈中删除。
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.