Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible see all the references to an object in execution time?

Tags:

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.

like image 508
Renato Dinhani Avatar asked May 27 '11 17:05

Renato Dinhani


People also ask

Are references and objects the same thing?

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.

How many references and objects are created?

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.

Can an object be a reference?

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.


2 Answers

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.

In the bottom area where is "Referências" shows the references of the selected object

like image 111
Renato Dinhani Avatar answered Oct 15 '22 11:10

Renato Dinhani


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.

like image 45
Peter Lawrey Avatar answered Oct 15 '22 11:10

Peter Lawrey