I am experiencing some out of memory issues on my app and want to call the garbage collector, but I am not sure in which method I should call it.
Here is my code:
public static void CleanUpMemory(){
System.runFinalization();
Runtime.getRuntime().gc();
System.gc();
}
Currently I am calling this method in onStop()
but is it better to call it inside onDestroy()
?
It is never a good practice to call the GC manually. Dalvik or ART simply knows better than us.
If your app requires a lot of memory to handle expensive operations, this is a good solution
<application
....
android:largeHeap="true">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With