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 profilers to do this, I only need know the references, no matters how.
A reference is an entity which provides a way to access object of its type. An object is an entity which provides a way to access the members of it's class or type. Generally, You can't access an object without a reference to it.
You have up to three references to two different objects. Note: unless your code does something useful with them the JVM can optimise this code away to nothing, in which case you will have no references or objects.
Objects are assigned and copied by reference. In other words, a variable stores not the “object value”, but a “reference” (address in memory) for the value. So copying such a variable or passing it as a function argument copies that reference, not the object itself.
Ok, Netbeans show all the references to an object.
First, run the project in debug mode CTRL + F5
, after, show the Loaded Classes Alt + Shift + 4
or Window->Debug->Loaded Classes
.
Choose the class will want to see the references and double click on it.
Pause the execution and there is.
In the top is the attributes of the object, and in the bottom, all references to it.
If you dump the heap and analyse it you get find all the references. Profilers like VisualVM and YourKit can do this for you.
However its not possible to determine this dynamically. If you want to know all the things which refer to an object you must maintain a collection these yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With