Is there a way to find all references to a specific instance of an object? from what I understand, while debugging, you get the address of every variable (for example, I have this={ListView@<Number>}
. I assume the number is an address)
I've tried using Find all references to object
, but it doesn't work (at the bottom of the IDE - not in the log - I've noticed something that says the object doesn't support that operation, and not surprisingly - it says "Collecting data" but I get nothing).
Is there any other way/trick? I can set a breakpoint to find the object, but when I go back in the stacktrace, it becomes harder to find the variable, since it's hidden inside other objects which are inside other objects etc.
Also, following the lines the stacktrace points to is a problem, since it doesn't actually point to the right lines...
This might be a bit late, but for anyone else looking for an answer - while debugging in Android Studio, right click on the object's instance and select Show Referring Objects...
. This will print a list of all objects that hold a reference to your object.
If you can insert a breakpoint at a place where the object is in scope and not nested too deeply within other objects, then Łukasz Paczos's answer is the way to go.
An alternative approach is to use Android Studio's Memory Profiler, as follows:
Steps 3-5 are demonstrated in the following screenshot:
Steps 6-7 are demonstrated in the following screenshot:
Steps 8-10 are demonstrated in the following screenshot:
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