INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

HANDLE


PASSWORD
Remember Me
Forgot Password?

Come Join Us!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • Turn Off Ad Banners
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

E-mail*
Handle

Password
Verify P'word
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Member Feedback

"...If there has ever been a justification needed for access to the net during working hours, just referring to this site should suffice. Fantastic!..."

Geography

Where in the world do Tek-Tips members come from?

 Max Heap , real free memory and GC invoke

antonas (Programmer)
29 Nov 02 9:30
Hi,

My question is about Garbage Collector invoking. Ash far as I know Garbage collector implicitly is invoked when it reaches maximum heap size assigned to the JVM. Lets say if I have
java -Xmx25m Blabla

So when JVM memory usage will reach 25M it will not be able to create more objects and will run GC tu free not strongly reffered objects. My question what if on my system is only 20 Mb available memory (lets say 10Mb RAM and 10MB virtual). Will GC be executed when it reaches phycical memory limit or it will throw OutOfMemoryError ?

Thank You very much

Tony
jfryer (Programmer)
1 Dec 02 18:30
The GC does run as you describe, but it also runs at other times, usually when the cpu is idle (no processing running) so it does garbage collecting at other times, even if the memory isnt maxed out.

In answer to your question I believe it depends very much on your programming.  If you have 25Mb of strongly referenced objects then your program with collapse in a heap because there is nothing the GC can remove, however, if you program smartly and null object references and other things to minimalise the number of strongly referanced types then the program will cope.

----------------------------------------
    There are no onions, only magic
----------------------------------------

antonas (Programmer)
2 Dec 02 4:26
Yes but my question is if GC will be invoked after physical free memory is no available. Situation is that I have created plenty of temporary objects in the loop. I explicitly null in the loop so they can be collected by GC. But The problem is (or may be) that I set Max Heap size of JVM to 25 Mb and before I start JVM I see that only 20MB of free memory is available. So again when my JVM reaches 20 MB does it starts GC or it still tries to achieve 25 MB and then runs out of memory ?

Thanks in Advance
idarke (Programmer)
2 Dec 02 15:27
You should realize that the answer will depend on your platform, since GC is implemented by the JVM and differs from one to the other.

For instance, on the Windows platform that extra 5M of heap you defined will result in your JVM using the swap file on disk.  You won't get an Out-of-memory error unless the swap file can't expand to cover it.   Setting it up this way will result in a very slow application.

The general rule is that you're not supposed to define the heap larger than the RAM available.
jfryer (Programmer)
3 Dec 02 15:16
So, yes, you will get a Out_Of_Memory error if you have consumed all of your heap space AND there is no more swap file space in windows (highily unlikely unless you have set your swap file to less then 5 megs in the first place). As for Linux etc I am not sure, but I expect the case to be similar.

You can try to call System.gc() to free up some space before the max is reached, although the JVM does not garantee that the gc will run when you call it (however in my experience it tends do, but don't bet on it).

You mentioned that you create a lot of temporary objects, can those objects not be reused instead of creating new ones?  I don't know your code or what you are trying to achieve, but I thought I would bring it up just to get you thinking about it (but of course you probably have already)


Does that kinda answer your initial question? Or am I rambling to much?

----------------------------------------
    There are no onions, only magic
----------------------------------------

antonas (Programmer)
4 Dec 02 7:49
Thanks for your response.

So if got it clear JVM does not starts gc when physical memory limit is reached. Thats actualy my question is. Its little hard to use System.gc because I can hardly say when I need to start it while I am sending objects via network in some encoded format. Object size can vary from very small to pretty huge. So I can not count on number of objects. Checking Runtime.freeMemory() after every object created is too expensive.

Of cource the best solution would be reuse an objects but I send objects via network in encoded files, and encoding API is written by third part. Tha API documentation defines that new object shoud be given (maybe its based on serialization)

Thank You

Start A New Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Promoting, selling, recruiting and student posting
are not allowed in the forums.
Posting Policies

LINK TO THIS FORUM!
(Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum)
TITLE: Java (Sun) Forum at Tek-Tips
URL: http://www.tek-tips.com/threadminder.cfm?pid=269
DESCRIPTION: Java (Sun) technical support forum and mutual help system for computer professionals. Selling and recruiting forbidden.

 

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close