tags:

views:

157

answers:

1

Hello.

Lets say i have loaded an image in a bitmap object like

Bitmap myBitmap = BitmapFactory.decodeFile(myFile);

Now what will happen if i load another bitmap like

myBitmap = BitmapFactory.decodeFile(myFile2);

What happens to the first myBitmap does it get Garbage Collected or do i have to manually garbage collect it before loading another bitmap , eg. myBitmap.recycle()

Also is there a better way to load large images and display them one after another recycling on the way

A: 

The first bitmap is not GC'ed when you decode the second one. GC will do it later whenever it decides. If you want to free memory ASAP you should call recycle() just before decoding the second bitmap.

If you want to load really big image you should resample it. Here's an example http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue/823966#823966.

Fedor