I've been doing some memory consumption tests over a MIDlet that is not working correctly.
The problem occurs in a Nokia 2630 (S40), and the message is "Error: Out of memory error. Java / lang / OutOfMemoryError c: Unable to expand"
I managed to find the exact point where the error occurs: An attempt to instantiate an object heavy enough. (It has over 2000 lines of code and makes use of several images of 128x160 pixels, is a map)
Out of curiosity, I wanted to know exactly how much "Heap" memory consume the object, so I measured in several mobile phones the total amount of "Heap" (Runtime.getTotalMemory), memory before instantiate the object (Runtime.getFreeMemory) and memory after instantiating the object (again Runtime.getFreeMemory)
The tests are quite surprising:
Before instantiating: 213kb
After instantiating: 201KB
I assume that there has been any call to the "Garbage Collector", because the object weighs more than the 12 Kb.
Before instantiating: 2.563Kb
After instantiating: 2.067Kb
I understand that the object may use about 500Kb of Heap.
Before instantiating: 9Kb
After instantiating: 308kb
I assume that during the execution, the program will consume virtually all memory Heap, and when trying to instantiate the object, it calls to the "Garbage Collector" to free enough memory. I do not understand in this case, why the running program and the instantiated object, consuming only 100 KB of total memory. It has dinamic memory?
Sony Ericsson k610i:
Before instantiating: 978kb
After instantiating: 961Kb
The most curious of all is that the Nokia 2630 has 600KB of "Heap", more than the N81 or the 6630, and yet can not instantiate the object, Why?
I try to make calls to the "Garbage Collector" several times throughout the program and of course before instantiate the object, but does not work.
Maybe the s40 has only a few Kb for images?