creación y destrucción de objetos java

I have a big bitmap, created with Bitmap.createBitmap(). Is there any sense in writing

bitmap = null;

justo antes

bitmap = Bitmap.createBitmap();

to let the GC use the memory occupied with the old bitmap while constructing the new bitmap.

The API level is 11.

Gracias por su atención.

preguntado el 09 de septiembre de 13 a las 10:09

what is your android version -

If really immediately before: no, there is no sense there. GC will know it. -

@Raghunandan Why would that make a difference? -

@Axel…. If it 2.3.3 and lower the calling recyle() on bitmap is necessary on 3.0 and higher bitmaps pixel data is stored on the heap -

absolutely none whatsoever -

2 Respuestas

bitamp = null; will not ensure that GC will release the memory occupied by bitmap object. Brcause as Bitmap is a final class so priority of final object is very low for GC. Use bitmap.recycle() method to ensure for Garbage collection(GC).

Respondido el 09 de Septiembre de 13 a las 10:09

Look at the video around 11:23. The guy talks about bitmap memory management

Its left to the garbage collector to free memory. Instead of bitmap = null utilizan el bitmap.recycle() on andorid 2.3.3 and lower. Use BitmapFactory.Options.inBitmap on 3.0 and higher

Android - ¿Gestión de memoria y mapa de bits?

On android 2.3.3 and lower

On Android 2.3.3 (API level 10) and lower, using recycle() is recommended. If you're displaying large amounts of bitmap data in your app, you're likely to run into OutOfMemoryError errors. The recycle() method allows an app to reclaim memory as soon as possible.

On android 3.0 and higher

The bitmap pixel data is stored on the heap

Android 3.0 (API Level 11) introduces the BitmapFactory.Options.inBitmap field. If this option is set, decode methods that take the Options object will attempt to reuse an existing bitmap when loading content. This means that the bitmap's memory is reused, resulting in improved performance, and removing both memory allocation and de-allocation.

Also check this might help

contestado el 23 de mayo de 17 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.