Solved

Working of Garbage Collector!

Posted on 2002-04-27
7
273 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 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

20 Experts available now in Live!

Get 1:1 Help Now