[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Missing post? - see this post about spam for more information.
system.gc  XML
Forum Index » Java Programming
Author Message
santo

Newbie

Joined: 10/03/2005 02:39:53
Messages: 4
Offline

garbage collections will be handled by JVM itself means ,how does it know that the object is no longer needed by the prgm.
memory recycling ,if i use system.gc whether it's a worst programming style or optimized one.


stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 884
Location: Superior, CO, USA
Offline

As a general statement you don't care if an object is no longer needed. But this means that you need to be careful. Unlike C++ you don't have an explicit destructor. Therefore you need to make sure you clean up after anything like database connections before the object goes out of scope.

I guess I'm not a fan of System.gc() - before the JVM throws an OutOfMemoryException it will do everything it can to clean up memory. If you're calling System.gc() it may help a little bit but I guess I question that it is going to do much for you. A decent Java program doesn't need to do it - know where memory is allocated and make sure you don't have references to it when youd don't want them.

Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
yawmark

Newbie

Joined: 06/24/2005 10:10:08
Messages: 13
Location: WDSM, IA
Offline

santo wrote:how does it know that the object is no longer needed by the prgm.

Overly simple explanation: the JVM will know to collect an object when it is no longer accessible by the code. Example:
[MSN]
 
Forum Index » Java Programming
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2012 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle