outOfMemory exception on device with 2mb memory

Hi all

I have experienced the following problem.

The application I have developed works fine on a sonyerricson w800i but gives outofmemory on a nokia 6131

The se800 reports 1048572 bytes available memory (1mb)

The nokia 6131 reports 2097152 bytes available memory (2mb)

For debugging purposed I do a System.gc() and report free memory, on average the se800 has 77% free whereas the nokia starts with 55% free and it degrades quickly.

Its the same application and code so does this mean the nokia has a problem? It is my code that is at fault?

When I first encountered outOfMemory exception I followed some guidelines removing any inner classes dereferencing object by obj = null and making sure I close streams etc, this helped with general memory consumption. I tested it with the emulator limiting memory to 400k and I have an average of 20% free.

I suspected the screensize to play a role as I paint the canvas manually but on the emulator I use the defaultcolorphone which has a larger screen than the nokia.

Where could the problem lie?

GX

[1111 byte] By [GXa] at [2007-11-27 5:02:26]
# 1
anybody?
GXa at 2007-7-12 10:20:15 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

First of all!

Nokia 6131 (my phone) has only 10 MB of storage by default. So I guess you are watching that the free space of the phone.

The outOfMemory refers to the ram memory used to run the apps, and the storage you are seeing is the free space to have data on it.

They are different things.

Now, assuming you are really refering you 2 MB of free RAM memory, then still you would be wrong. Becausse java app has a limit of how much memory can use by an app. this is different from device to device. probably you are using an array or something like that too big to be kept in memory (different from storage cards).

MelGohana at 2007-7-12 10:20:15 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

Hi MelGohan

Thanks for your reply. In order to test how much free memory I am using the following method:

public static String getFreeMem()

{

System.gc();

long tot = Runtime.getRuntime().totalMemory();

long free = Runtime.getRuntime().freeMemory();

int per = (int)(((float)free / (float)tot) * 100);

String s = gx.Utils.padString(String.valueOf(free), -8, " ") + " " + gx.Utils.padString(String.valueOf(per), -3, " ") + "%" + " / " + String.valueOf(tot);

return s;

}

There are no other applications in memory as I tried restarting the phone and the results were the same hence I can see exactly how much memory is available (2097152 bytes) and how much is free/used.

On the emulator and the sony erricson the memory usage is stable whereas the nokia keeps using more and more, I am currently setting all unused objects = null when done using them but have found no difference so far.

I have put the same post on the nokia boards and there is more info there:

http://discussion.forum.nokia.com/forum/showthread.php?t=108401

GX

GXa at 2007-7-12 10:20:15 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

well you are getting the memory of all your device not the asigned for your app, try to find the line of code that has the problem and check if you can optimize it. You may be getting the free memory at a non critical moment, I mean where is not high memory usage, so try to find the line code that makes you run out of memory to try to fix it, I guess there are not more advices

MelGohana at 2007-7-12 10:20:15 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
Thanks for the advice MelGohan My question was however not why am I getting the memory errors but more why is the memory consumption on the nokia so high and why is it not getting released whereas on the emulator and the sonyerricson it is fine.GX
GXa at 2007-7-12 10:20:15 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6
I guess because different devices has different memory assigned for apps. And is not the whole memory of the system.
MelGohana at 2007-7-12 10:20:15 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7

Are you creating many canvases? I am not sure about your device, but I have run into this issue when working with the nokias.

http://www.forum.nokia.com/document/Forum_Nokia_Technical_Library/contents/FNTL/Creating_too_many_Canvas_instances_throws_outOfMemoryException_.htm

I think there is similar bug for creating many Form objects also.

You should be able to find out if the heap memory is shared on docs on forum nokia.

rashidmayesa at 2007-7-12 10:20:15 > top of Java-index,Java Mobility Forums,Java ME Technologies...