This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "garbage collection" Watch "garbage collection" New topic
Author

garbage collection

Rakesh Gulati
Greenhorn

Joined: Jul 06, 2000
Posts: 4
how destruction of objects take place in java as compared to C++, with that I mean that in C++ by explicitly destroying objects I can know at any point of my program that how many
objects of the class are existing at any point of time(by incrementing in the constructer & decrementing in the destructer a static variable and destroying objects with pointers). But in Java you are never certain about garbage
collection(and hence finalization) so how in java I will come to know about the count of number of objects of a class at any particular point in a program.
ricky gonzalez
Ranch Hand

Joined: Jun 30, 2000
Posts: 167
You can keep track of the objects you have by not de-referencing them. By that, I mean always keep a reference to the objects. What good is an object if you can not access it anyways?
Gopinath Rajgopal
Ranch Hand

Joined: Jun 26, 2000
Posts: 31
Rahul, in case you want to keep track of the number of objects of a class you have, you can do so just as in C++. Increment a static counter variable in the constructor and decrement it in an overrided version of the finalize() method. Hence, just before garbage collection of this object, finalize() is called and you can decrement the counter.
Note however that this count will only indicate how many UNCOLLECTED objects you have - NOT how many you have access to. As Ricky says, what good is an object if u don't have a reference to it ?!
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: garbage collection
 
jQuery in Action, 3rd edition