Is it possible to obtain all references to an object in Java.
What I need to check is if an object has removed all subscriptions for callbacks.
Thanks
One approach would be to keep a list of weak references to all objects to which subscriptions have been requested. Whenever the object subscribes to another, add to the list a weak reference to the other. Whenever the object unsubscribes, remove the weak reference. Verify that all subscriptions have been removed by checking that the list is empty.
If necessary, this can be generalized for objects that support multiple types of subscriptions.
A false positive can occur if a subscription is not accompanied by adding to the list.