×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Sep 2005
    Posts
    138

    Heap memory problem in Nokia s40

    Hello!

    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:

    Nokia N81:

    Total: 512K
    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.

    LG-KP 500:
    Total: 5.242Kb
    Before instantiating: 2.563Kb
    After instantiating: 2.067Kb

    I understand that the object may use about 500Kb of Heap.

    Nokia 6630:
    Total: 400Kb
    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:

    Total: 1.572Kb
    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?

    Thank you!

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Heap memory problem in Nokia s40

    It is complicated to compare memory usage between different devices, as the memory management can be very different. I suggest you start by reading Java Memory Management in the wiki. At the end of that, you'll find a link to an article specifically about images and memory.

    Nokia N81 and 6630 are Series 60s. The heap will expand when it fills up, so don't just look at the free memory - you need to look at how the total memory has changed too.

    Series 60s and man Sony Ericsson devices will store image data outside the Java heap. The Java object is just a "stub" that contains a reference to the external object (like a "resource handle"). On Series 60, the image is held in Symbian's resource manager. Sony Ericsson devices often have a special, optimized "image heap" - a separate area of memory, more closely coupled to the video hardware. The Runtime methods won't show other heaps.

    You should expect an image 128x160 to consume between 40 and 80k of... whatever heap is involved. More heap might disappear, as memory will be consumed by loading the data from the file and decompressing it. You should always manually call System.gc() before taking memory readings, or you're counting garbage too.

    I recommend you never call System.gc() as a routine part of your application. It's not necessary, and may slow down your application, especially on Series 60.

    Hope that sheds a little light...

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Sep 2005
    Posts
    138

    Re: Heap memory problem in Nokia s40

    Hi Graham!

    Thank you for your answers. I have readed the articles and are very good. See you!

Similar Threads

  1. Problem by allocating big memory on heap
    By paipeng in forum Symbian C++
    Replies: 2
    Last Post: 2010-02-18, 09:27
  2. Memory Heap & OS Heap
    By earamsey in forum Mobile Java General
    Replies: 0
    Last Post: 2007-08-27, 23:02
  3. Heap memory problem
    By lauyk001 in forum Symbian C++
    Replies: 1
    Last Post: 2004-11-25, 03:23
  4. Memory problem on s40
    By fwojtek in forum Mobile Java General
    Replies: 1
    Last Post: 2004-04-28, 09:10
  5. Problem with heap memory on 3650
    By jridenou in forum Mobile Java General
    Replies: 2
    Last Post: 2003-08-26, 20:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •