is there an elegant way in Java to set all existing object-pointers to null?
I want an object to be deleted, but it is registered in several places an Event Listener.
is there an elegant way in Java to set all existing object-pointers to null
Share
You can take a look at References. If you use a reference to refer to the class, it will not prevent an object from being garbage collected when all of the regular references are removed. The references held by the
Referenceclass doesn’t count when the collector determines which objects to collect. Of course, the listeners will have to correctly handle the reference suddenly disappearing. And you’ll have to make sure something’s keeping a regular reference for as long as you need to class to stick around.Check out this thread for a discussion about the differences between the soft and weak references. What is the difference between a soft reference and a weak reference in Java?