Solved

Working of Garbage Collector!

Posted on 2002-04-27
7
275 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
github account with ecipse 1 47
Oracle SQL syntax check  without executing 6 50
reverse digits of a number using for loop 5 40
Tomcat: Unable to run tomcat service. 2 18
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now