Does Java Garbage Collector free the unused memory

Hi All,

I have a small doubt regarding the java garbage collection. When I place System.gc() in my code, it will invoke garbage collection. But it's up to JVM to call garbage collector or not.

My doubt is can JVM free the memory physically?

Why because Virtual machine will be allocated virtual copies of resources of the system. (I read this in Virtual Machine's concepts).

Thanks in advance,

Kishore.

[443 byte] By [vvkkishore123a] at [2007-11-27 5:15:27]
# 1

> I have a small doubt regarding the java garbage

> collection. When I place System.gc() in my code,

Don't do that unless you have a good reason.

> it will invoke garbage collection.

No, it won't. It justs asks the GC nicely. It may still decline.

> But it's up to JVM to

> call garbage collector or not.

> My doubt is can JVM free the memory physically?

Not sure whether it does, I actually don't think so. GC only cleans the heap, but doesn't touch the memory allocated for the entire process. Might even be unspecified behavior.

CeciNEstPasUnProgrammeura at 2007-7-12 10:37:41 > top of Java-index,Java Essentials,Java Programming...
# 2

As far as I know, the JVM will free virtual memory (heap memory) but not physical memory. When you call the GC it will free the heap and the physical memory will stay almost the same since the JVM assumes that this chunk of memory will be used again. Therefore, it keeps it to speed up further requests. If your memory keeps going up, this means you probably have a memory leak.

BD.

BinaryDecimala at 2007-7-12 10:37:41 > top of Java-index,Java Essentials,Java Programming...
# 3

the JVM MAY release memory that's no longer needed, but there is no guarantee that this will actually happen (iow, it depends on the JVM internal implementation which may or may not change without notice in between even minor releases).

So do not make any assumptions, it's the only possibly safe way to act.

jwentinga at 2007-7-12 10:37:41 > top of Java-index,Java Essentials,Java Programming...