If I have:
Bitmap bitmap = Bitmap.create(..); // instance a bitmap = Bitmap.create(...); // instance b bitmap = null; bitmap = Bitmap.create(...); // instance c bitmap.recycle(); bitmap = Bitmap.create(...); // instance d bitmap.recycle(); bitmap = null;
Once this code is executed, which of the 4 instances is still in memory? I know .recycle () instructs the native code to release all resources to this object, but there is no guarantee when this will happen.
The reason I'm asking for allows you to take a look at the following cycle:
Bitmap bitmap = null; while (true) { bitmap = Bitmap.create(...); }
I assume this will cause the application to crash (from memory)? If so, how should this cycle be rewritten? (If I use a bitmap to animate and display the changed state).
Java ( Android) . , . , * , , .
, , , Bitmap , - , , , .
Bitmap
; , , GC , , . GC , ( ).
JVM/ART , OutOfMemory, , , . - , .
OutOfMemory
, Bitmap; -, , Bitmap, ( , ).
* , , PhantomReference, , GC , , - - .
PhantomReference
Android DalvikVM, Java. , .
MAT - memeory hprof android.
, MAT