Does bitmap really have to be recycled?

Problems with Canvas, OpenGL, etc...

Does bitmap really have to be recycled?

Postby tenfour » Sun Oct 10, 2010 10:23 pm

In all the NeHe OpenGL tutorials for Android, the bitmap is recycled after the texture is loaded. Is this really required? Won't the GC take care of it anyway?

Does the line
bitmap = BitmapFactory.decodeStream(is);
basically create a new Bitmap object and cause the any pre-existing Bitmap to be unreferenced and therefore eligible for garbage collection?

In my application, I'm trying to load bitmaps to memory in a separate thread. So I need my bitmap reference to be a class variable so I can use it in multiple methods.

Thanks.
tenfour
Freshman
Freshman
 
Posts: 7
Joined: Mon Aug 23, 2010 10:55 pm

Top

Re: Does bitmap really have to be recycled?

Postby moblcade.com » Mon Oct 11, 2010 7:00 pm

No, it does not have to be recycled, but it's recommended. There's a hard limit to the amount of memory your Android process can allocate. Right now I think it's 16MB. It is easy to surpass that limit when you are uploading a series of bitmaps to video memory if you do not recycle them after you upload them. Even though a PNG image may only occupy 300k or so on disk, when that image is loaded, decompressed and stored in memory this image may occupy megabytes.

Keep in mind that you should only recycle bitmaps you no longer intend to use. This includes bitmaps you've uploaded to the video card with OpenGL for use as a texture.
moblcade.com
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Sep 07, 2010 6:31 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 3 guests