Memory Allocation in Java - Android

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).

+5
source share
2 answers

Java ( Android) . , . , * , , .

, , , Bitmap , - , , , .

; , , GC , , . GC , ( ).

JVM/ART , OutOfMemory, , , . - , .

, Bitmap; -, , Bitmap, ( , ).

* , , PhantomReference, , GC , , - - .

+1

Android DalvikVM, Java. , .

MAT - memeory hprof android.

, MAT

0

All Articles