Solved

Working of Garbage Collector!

Posted on 2002-04-27
7
279 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Industry Leaders: 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!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

717 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