Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Working of Garbage Collector!

Posted on 2002-04-27
7
276 Views
Last Modified: 2013-12-29
Hi, i have a java application, which i started with the heap memory of say 256MB. My question is, if the application exceeds this 256MB, and the application is trying to allocate some memory in heap, will the garbage collector release some object's memory from the heap, even if the object is referenced but not used for long time or using some other rules?

TIA
0
Comment
Question by:vijaynatraj
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 6972997
As a preliminary (it should not be seen as final) response to your query:
1. The behaviour of individual VMs is different and specific
2. As a general principle, in the situation you described, if your application has hard references (references that should not be garbage collected) then what will happen is that the VM will throw an OutOfMemory error.

Some control can be achieved over this situation by use of java.lang.ref.SoftReference
0
 
LVL 35

Expert Comment

by:girionis
ID: 6973002
 As CEHJ said, garbage collection differs from VM to VM. But no VM will release memory from objects that are still referenced.
0
 
LVL 4

Expert Comment

by:pellep
ID: 6974464
This is how the sun JVM works (or so I've heard). If the VM reaches the end of the heap size and you try to allocate more heap memory, it will attempt to run the garbage collector to see if it can free up some memory. If enogh memory still can't be freed, teh garabge collector will throw an OutOfMemory error. This may not be what you asked for though. The previous posts answers your question. Referenced objects won't be garabge collected.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:vijaynatraj
ID: 6974469
The problem is, we intialized the max heap size with 256MB, we are running our application in an system with 256MB ram, 800MB virtual memory. But still, our application's total memory is not going beyond 220MB (Viewed using Task Manager). But once it reaches the 220MB, it is hanging for some 10-20 mins after that the total memory size is coming down by 3-4MB, allowing you operate for some more time, again reaches 220MB, and it is continuing in this way repeatedly.

When we used the JPurify, it is showing different picture, there is a free memory and allocated memory (not exactly 220MB but very much less than that). Free memory is decreasing and allocated memory is increasing when we do some operation in our application. Once the free memory reaches zero or having memory in hundered bytes or so, GC is starting and it collecting some memory from the allocated memory and putting it in the free memory and it is continuing this way but this is happening frequently.

My question now is,
    Why in the task manager of windows, the intermediate GC collected memory is not reflected? It is keep on increasing except some minor decreases, until it reaches the 220MB or so.

Thnx for ur answers.

0
 

Accepted Solution

by:
albertlee earned 75 total points
ID: 6979391
It does not release the memory to the system. The free memory is blocks of memory in the VM heap which no references refer to.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7992307
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
split between: albertlee, CEHJ
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8048458
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

CEHJ points for you at:
http://www.experts-exchange.com/jsp/Programming/Programming_Languages/Java/Q_20534825.html
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question