Sign in to follow this  

Phone Heap Memory

This topic is 3739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok here is something Im finding confusing. I just recently mistook heap memory for stack memory but no, heap memory is the total memory available for your program. When you realise a good recent phone only has 2MB worth of heap memory you realise why J2ME requires so much optimisation. My greatest worry now is images: a 240x340x24bit screen will consume 225kb of heap for each image. That means it cant hold in memory more than 10 images like this. Thats a huge bottle neck on the entire system. I was using a sprite class to display a small full screen animation for my splash screen. 10 different screens at 3 seconds each is not that much (company name, game name, small intro, credits, etc) but it wont work since it will burst the memory clean. Am I reading this correctly? Is this really how it works? I was worried about compressing images so that the jar would be small enough... should be worried about the heap size instead. Does anyone know how much of a performance bottleneck is loading each image at the time to show it? would it work nicely for the splash? I can try this on my 6230i and the 6300 but those are all the handsets I have available. Yours Truly K

Share this post


Link to post
Share on other sites
Quote:
Original post by BloodWarrior
Ok here is something Im finding confusing.
I just recently mistook heap memory for stack memory but no, heap memory is the total memory available for your program.

When you realise a good recent phone only has 2MB worth of heap memory you realise why J2ME requires so much optimisation.

Heap, fragmentation, IO latency, and speed are all parts of J2ME that you learn to deal with and eventually pick up tricks and optimizations you can reuse later.
Note, that the 2MB you are speaking of is shared memory as well, so included into the amount you can use is the class files too. Say for example you have the 2MB of memory available and you have a lot of unobfuscated class files that equal 200Kb, than you lose that 200Kb immediately from the heap at runtime.

Quote:
Original post by BloodWarrior
My greatest worry now is images: a 240x340x24bit screen will consume 225kb of heap for each image. That means it cant hold in memory more than 10 images like this.

I almost NEVER use fullscreen 24bit images. This is for a number of reasons; one of course is the heap impact and another is the filesize.

Quote:
Original post by BloodWarrior
Thats a huge bottle neck on the entire system.
I was using a sprite class to display a small full screen animation for my splash screen. 10 different screens at 3 seconds each is not that much (company name, game name, small intro, credits, etc) but it wont work since it will burst the memory clean.

There really are a lot of things you can do to get past this. The easiest way is to break your large images into smaller images that will not cause as much fragmentation. For the splash screens another trick is to create a smaller size centered image that you can draw on top of a static color background. If you also know that you will no longer need those splash screen images once they are used you can delete them and remove them from memory when they are done being used.

Quote:
Original post by BloodWarrior
Am I reading this correctly? Is this really how it works?
I was worried about compressing images so that the jar would be small enough... should be worried about the heap size instead.

Unfortunately this is how it works. Note that a lot of optimizations you can make to help file size (obfuscating code, breaking large images into smaller images, resource packing, etc.) can also have a positive impact on heap usage.

Quote:
Original post by BloodWarrior
Does anyone know how much of a performance bottleneck is loading each image at the time to show it? would it work nicely for the splash?
I can try this on my 6230i and the 6300 but those are all the handsets I have available.

Any performance bottleneck is not going to be standard across all of the screens. Some load images slowly, others very quickly. Generally speaking though, for splash screens, since you are going to be waiting for a period of time to show the information what you can do is blit the image to the screen and then while you are waiting to proceed load up the next image.

When you feel like you need to get your game out there and test, post a thread around the forums asking for beta testers. Also check out
  • This topic is 3739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

    If you intended to correct an error in the post then please contact us.

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    Sign in to follow this