简体   繁体   中英

Is it a good practice to use Runtime.getRuntime().gc() method in onDestroy() of an Activity?

onDestroy() method of an Activity does not reduces my memory usage. I am allocating some memory onCreate() of an Activity, but onDestroy() of that same activity does not de-allocates the memory as seen in the Android Monitor.

So, I was using the Runtime.getRuntime().gc() method to clear the memory manually. I was calling it in onDestroy() method.

Is it a good practice ?

I was using the Runtime.getRuntime().gc() method to clear the memory manually

That does not "clear the memory".

When I am opening a new activity, the memory allocation takes place. If I go back and forth, the memory keeps stacking up

Then you have some form of memory leak. Use the development tools to determine where the problem is coming from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM