?
Solved

Working of Garbage Collector!

Posted on 2002-04-27
7
Medium Priority
?
280 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
[X]
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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses

765 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