Release Memory of Particular Activity when it is Destroyed Release Memory of Particular Activity when it is Destroyed android android

Release Memory of Particular Activity when it is Destroyed


Add following code for it

@Overrideprotected void onDestroy() {    //android.os.Process.killProcess(android.os.Process.myPid());    super.onDestroy();    if(scaledBitmap!=null)            {                scaledBitmap.recycle();                scaledBitmap=null;            }     }


In activity if you're calling the finish() method from is destroyed and all its resources are queued for garbage collection.

So, all memory that was used by this activity will be freed during next GC cycle.

OR

you can try this to clean memory,

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

check this details. hope that helps.


Try to set the bitmap to null while activity is destroyed and if desire run the garbage collector.