Where do references to Java objects actually exist? (Such as for Garbage collection)
Strong references are not recycled during garbage collection.
The hprof file appears to record the connections between objects.
Where do they exist in the JVM? I guess there's code to maintain it, too? Does it have anything to do with object headers?
void setView(View view) {
// This is a “reference” to the view
this.view = view;
}
Question:
- Where do the actual references exist?
- If not, where did the
hproffile come from?
Like all other programs, a variable or object resides in memory. A program or function is loaded into the memory before execution along with the function arguments and other variables. Static variables along with function arguments are stored in the stack of the memory layout whereas the dynamic memory allocations are done in the heap segment of the program stack layout. If you are confused about the program stack layout/frame, I would recommend checking this answer here.
I am not sure about this one. As far as I know, it creates the dump from the heap when demanded by the program executor. This is just a file which has the heap dump. In the case of Android, this should be created when you run the profiler and add specific instructions to create the heap dump for you. However, I am not certain about this. This is an old video, which might give you an idea on how you can generate a
hproffile. The developer's documentation tells you how to create a heap dump as well.