0

我们如何在销毁时回收活动资源?我们是否有可能从内存中删除 Activity 并立即回收资源?如何在 Android 中释放 Ram 资源?我知道如何使用 Process.killProcess(Process.myPid()) 杀死应用程序并回收资源,但我希望这适用于具有多个活动的应用程序,我们只从内存中删除单个活动..

4

1 回答 1

2

How to reclaim memory of single activity on destroy?

So long as you are not holding onto the activity via some static reference (e.g., static data member, background thread, etc.), the activity will be eligible for garbage collection after onDestroy() completes. If you are concerned that perhaps you are indeed preventing your activity from being garbage collected, use MAT to try to determine what is keeping it around.

Is is possible that we delete Activity from memory and reclaim resource immediately?

No, no more than you can "delete" anything in a garbage-collected runtime environment.

How to free Ram resource in Android ?

Let go of the "Ram resource" when you no longer need it, and it will be garbage collected.

I know how to kill an application using Process.killProcess(Process.myPid())

Please don't do that.

于 2012-08-19T15:02:43.100 回答