Computing.Net > Forums > Programming > Java destruction of objects

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java destruction of objects

Reply to Message Icon

Name: Colin Williams
Date: June 15, 2004 at 16:55:53 Pacific
OS: Redhat 9
CPU/Ram: AMD Athlon XP 2200+ 512MB
Comment:

I am writing a program that requires me to keep track of how many copies of a certain object are in creation at any given time. There are several ways that I have thought of doing this:

1) This is the most simple. I create a static int which is incremented each time an object is created in its constructor. Then, I provide a function to be called just before the object goes out of scope. This function would decrement the counter. However, this approach would require the client to manually call this function, and could lead to erroneous counting.

2) I was wondering if there is a way to include a "destructor" in a object, similar to C++. I have not heard of one, but it would be nice if there is one.

3) If there are any other ways to accomplish this, please do tell.

Thanx.



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: June 15, 2004 at 17:44:49 Pacific

Response Number 2
Name: anonproxy
Date: June 15, 2004 at 20:28:52 Pacific
Reply:

No, finalize() is the closest thing. There is a reference API. You might consider manipulating the reference queue.



0

Response Number 3
Name: gpp
Date: June 17, 2004 at 05:46:14 Pacific
Reply:

Are you using threading? If so, activeCount() will return the number of threads. Writing your own method may work ok, but will probably be inaccurate anyways.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Java destruction of objects

Array of objects in Java www.computing.net/answers/programming/array-of-objects-in-java/12255.html

java Serialization of objects www.computing.net/answers/programming/java-serialization-of-objects/14269.html

Array of Objects 2 www.computing.net/answers/programming/array-of-objects-2/14653.html