Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 06:25, 29 July 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to calculate memory used by images in Java ME

From Wiki
Jump to: navigation, search

This article explains how to determine the "real" memory consumed when loading an image in Java ME.

Article Metadata
Tested with
Devices(s): S60, Series 40 All
CompatibilityArticle
Created: Tiger79 (09 Sep 2009)
Last edited: hamishwillee (29 Jul 2013)

Introduction

It is not uncommon for developers to get an "Out of Memory" Exception when running MIDlets containing many Images and/or a single big Image.

Often this is unexpected - the file-size of the Images wouldn't appear to put the app in danger of going over app memory limits. This is because people assume that a 7 kilobyte Image which is a 240x320 pixels plain white Image shouldn't create any memory problem, after all it's just 7 kilobyte!

Unfortunately, this assumption is incorrect!

Solution

Internally the OS will create a Bitmap-type mapping of the Image to be able to actually display it. This means that a 240x320 pixels Image will consume:

width x height x (color depth/8)

Let's say we got a screen with 16 bit colour-depth and a 320 x 240 pixels Image. This will result in: 320 x 240 x 2 = 153600 bytes. 150 Kb is a lot more than the 7 Kilobyte of the original Image file-size !

So now that you know what the size and memory usage of an Image means for you as a developer you will be more aware on how to use Images and know what the impact of an Image might be on the memory usage of your application.

This page was last modified on 29 July 2013, at 06:25.
118 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×