Garbage Collector seems not to run

Hi!

I have a problem with the garbage collector:

To free memory, I regularly run the garbage collector in my app ( System.gc() ) after releasing resources by setting the reference variable to "null". But after some time I get an "out of heap memory" error. It seems that the gc doesn't run - I get the following result on the stdout:

0 garbage collections (0 bytes collected)

Is this possible? Or can I fix this problem?

Thanks for your help

[486 byte] By [asommer1] at [2007-9-26 10:56:03]
# 1

Is it that the GC was not kicking-in even when you delete the references to the objects? That is true for any GC. GC will kick in only when you need more memory to create new objects

Also, you need to tune your young generation space and increase it from default 2MB to 32MB which will avoid frequent young generation GCs. By setting Xmx to 1024 MB, VM will try to grow till 1024 MB and if it can't allocate because

of less physical memory on your system, it will throw OutOfMemory errors.

I suggest you try the following:

1. Configure young generation to 32MB and old generation to 512 MB. This is how

you start your app

java -XX:MaxNewSize=32m -XX:NewSize=16m -Xms64m -Xmx512m -verbose:gc <app>

This sets the initial heap size to 64MB. You can increase this if your initial startup memory requirement (static memory) is higher that 64MB.

With Xmx set to 512MB, if some sessions die or are closed and heap size grows to 512MB, Full GC should kick in and you should be able to release memory for new sessions. Running with -verbose:gc will show if Full GC gets kicked in or not.

2. Try can calculate the static memory required at any point of time and also how much garbage is collected in certain time period. Then using these values we can make changes in young and old generation sizes.

mfali at 2007-7-1 23:41:07 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

Thanks for your answer.

Yes, the problem is indeed that the gc doesn't run even if I delete the references and invoke it "by hand". If I understand you correctly you are talking about this problem on the "normal" J2SE version of Java.

My problem occurs with J2ME (Micro Edition) on a Palm Handheld. There I don't have this much of memory available and the gc is a bit different from the standard edition in that it doesn't run automatically. As far as I know I can't give any parameters to java on the device. So your proposition doesn't work.

Hope there exists a solution...

asommer1 at 2007-7-1 23:41:07 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
As I saw today, only with POSE (Palm OS Emulator) the gc seems not to run. With the "DefaultGrayPhone" I get the message that the gc has run, i.e.:18 garbage collections (127592 bytes collected)How is this possible? Isn't POSE fully supported by KToolbar?
asommer1 at 2007-7-1 23:41:07 > top of Java-index,Java Mobility Forums,Java ME Technologies...