• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how System.gc()'s work depends on the machine?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am trying to run some code sample from my Java book, and the output is not the same as in the book: the programm ends before the gc() does it's job. i have tried both jdk1.2.2 and jdk1.3.1_01, but there is no difference (actually, there is: on jdk1.3.1_01 the programm ended even more quickly). then i've did it on another computer, and it worked just as in the book example. why?
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you working on same OS on both computer, with same configuration?
Normally, GC won't start collecting object until your memory begins to be full. One thing to know,
there is an initial heap size and a maximum heap size. I'm not sure how the initial and the maximum heap size is calculated, but you can modify it this way:
(Originally posted by Jessica Sant)
Heap can be defined with the following params: -Xms<size> set initial Java heap size -Xmx<size> set maximum Java heap size
You may find somme interesting linkshere
and here
So, as I understand there is a corellation between your RAM and the Heap size.
Hope it helped you
[ June 21, 2002: Message edited by: Younes Essouabni ]
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The methos gc() implies that the JVM will make a best effort (null effort) for colelcting garbage.
But you can never assume that it will recover garbaje
 
Helen Tal
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks everybody,
i've just forgotten to say that my program (its not mine really,its an example from the book) calls System.gc() explicitly. and that yes, there are different OS's: Win98 and Win2000.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SYstem.gc() will not cause garbage collection to be executed. You should consider it no more than a suggestion to the JVM that garbage collection might be a good idea right now if it isn't too inconvenient.
 
Helen Tal
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, but what i don't understand is why when i run this program on the first computer the garbage collector always collects all the objects, but if i do it on the second computer, it collects only part of them.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are the two computers running different JDK versions? There have been a number of improvements (and more rarely, new bugs) in garbage collection, coming out in each new JDK release. You may also see differences because of different OS's on the computers (which may lead to different JDK's) or because the JVM's are allocated different amounts of memory. A JVM with little heap space available will usually work harder to free memory than one with a lot of heap available. (At least, this is true if you're right at the limit - not sure otherwise.)
To see what's going on with GC I like to run with java -verbose:gc. This reports all GC activity. I find that often if I call System.gc() twice in a row, the second call manages to collect some things that weren't collected the first time. If I want to be really sure that it's collected everything it's going to, I call gc() three times in a row; the third time almost never adds anything new. (There's still no guarantee everything has been collected, but if you can call 20 more times in a row and see no change, that's a good clue.) Obviously this makes the JVM work harder, and usually it's not very useful, but it's good for studying memory usage and figuring out which objects are eligible for collection. As long as you're not too concerned about performance at the same time.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I reread your posts above. It seems you're comparing the same JDK across two slightly different OS's. How much RAM is available on each computer? And how much of this RAM is being used by java.exe when it runs? If one system is unable to keep the whole JVM in RAM, the JVM may work harder to collect objects, to avoid using virtual memory since it's much slower. This is just a guess, but seems plausible to me at least.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic