How can I find out that an object (or class object) is not in use and is ready to be assembled By GC or how can I know that the application is running, there is no reference to that object. (Before being GCed)
I think you mean that when an object is detected Instead of using something, you can check it steadily.
The easiest way to inform is that the object is going to be GCs, ultimately to override the () method. Note: You have to be careful what you do in this method. As it is single threaded and blocked, resulting in no object being cleaned.
Another way is to use a weak or soft reference and monitor one reference queue. This is a way to monitor when an object is found to be cleaned as available. See the source of WeakHashMap for an example.
Note: There is no easy way to detect any object, without GC now in use, and if you have no GC for a long time, you have no way of knowing this is not.
Comments
Post a Comment