Is there a way to see all the references to an object in execution time?
I\'m using Netbeans, does this feature exist in it?
EDIT: No problem in using profil
Sorry, was not clear. I want the references in the execution time. All the refereces of a created object
Unfortunately, there is no such feature available in Java. But, there is a way of being notified that there is no more reference to an object at runtime.
The solution is to create a weak reference to the monitored object and associate it with a reference queue. When there will be no more hard reference to that object, the GC will sooner or later recollect it and enqueue the weak reference. You can check this with isEnqueued().
If you provide more information about your issue, may be we can give more tips & tricks.
EDIT
To control all references to an oject, you may use the Proxy Pattern. Instead of setting references to your connection object, you create a proxy object containing a private instance of the connection object. Then, have your code call the proxy who will call the connection object itself, instead of having direct references to the connection.
When you are done with the connection object, close it inside the proxy object. If other parts of the code still try to access that connection objects via the proxy, you will be able to detect it in the proxy when it is called.
It is a trick you can use to find which part of the code is still 'referencing' your object, so to speak.
Hope this helps.