Too many bitmaps causing an out of memory error!

Mickster

Active Member
Licensed User
Longtime User
Hey guys,

So I've developed an app with 5 different activity modules representing 5 different 'pages'. The app uses a ton of .png images for graphics and I have hit an 'out of memory' error. I've found a few posts discussing this error on the forum, but so far I haven't figured out how I can free up the memory.

The application doesn't need all the images loaded at the same time, so I've been looking for a way to remove them from memory when the user jumps between pages.

To apply the graphics, I've been using the .setbackgroundimage(loadbitmap... routine.

Any ideas? Am I using an inefficient command for loading images? Is there a way to remove them from memory without destroying the objects they're attached to (I need to preserve the objects)?

Thanks.
 

Mickster

Active Member
Licensed User
Longtime User
Thanks for the help.

I may not have a real solution but at least I know I'm not missing anything here. :)
 
Upvote 0

eps

Expert
Licensed User
Longtime User
The exact truth about Bitmaps and memory release seems impossible to to know!
Lots of learned people have conflicting views.

I'd tend to believe post #80:



Which all sounds very authoritive and knowledgeable.

The key problem though is not the process of freeing memory but the very vague timescale it can take for memory to be freed.

Memory used by a Bitmap is not fully freed until the garbage collector has run at least twice.

Calling a Bitmap's recycle() method sooner rather than later makes it more likely that the memory release process will start sooner rather than later.
Once the recycle() method has been called that Bitmap is marked as a candidate for destruction.

You cannot force the garbage collector to run - you can only request that is run.

So with no control over when the garbage collection takes place you have no control over when the memory will be fully freed.

Martin.

That part of the process doesn't free the memory, but indicates that it can be re-used. If the JVM will encounter an out of memory exception it will see if it can free up some memory to avoid that occuring.
 
Upvote 0
Top