I am writing a MIDlet using LWUIT, and the images seem to absorb an incredible amount of memory. All the images I use are PNGs and are packaged in a JAR file. I load them using the standard Image.createImage (URL) method. An application has several forms, and each has several button shortcuts, however, I am sure that only the active form is stored in memory (I know that it is not very reliable, but Runtime.freeMemory () seems to confirm this).
The application has proven itself in the resolution of 240x320, but moving it to 480x640 and using the corresponding larger images for the user interface causes errors in memory. That the application, among other things, uploads deleted images. The application works fine until it reaches this point. After loading several PNGs and returning to the main menu, an error occurs from the memory. Naturally, I looked at the amount of memory that the main menu uses, and it was pretty shocking. These are just two tags with images and four buttons. Each button has three images used for style.setIcon, setPressedIcon and setRolloverIcon. Images range from 15 to 25 KB, but when deleting two of the three images used for each button (a total of 8 images), Runtime.freeMemory () showed a stunning 1 MB memory reduction.
As I see this, I either have a lot of memory leaks (which I donβt think I do, but the memory leaks are not exactly known, which are easily tracked), I am doing something terribly wrong with image processing or there really is not a problem and I just need to zoom out.
If anyone has the opportunity to offer, I would really appreciate it.
java-me midlet lwuit
Marko
source share