java - 对 Java 对象的引用真正存在于何处?

标签 java android jvm hprof

Java 对象的引用实际存在于何处? (比如垃圾回收)

在垃圾回收期间不会回收强引用。 hprof 文件似乎记录了对象之间的连接。 它们在 JVM 中的什么位置?我想也有维护它的代码?跟对象头有关系吗?

void setView(View view) {
    // This is a “reference” to the view
    this.view = view;
}

问题:

  1. 实际引用文献在哪里?
  2. 如果不是,hprof文件是从哪里来的?

最佳答案

Where do references to Java objects actually exist?

内存中。在堆中,或在线程堆栈中,或(在某些情况下)在 JVM 知道的其他位置。永远在内存中。

Strong references are not recycled during garbage collection.

嗯……不确定你在这里真正说的是什么。 GC 不会回收引用,因为它们始终作为其他内容的一部分保留。

The hprof file appears to record the connections between objects.

确实如此。

Where do they exist in the JVM.

连接是引用。如果对象 a 在其实例变量之一中引用了对象 b,则 a 将显示为“已连接”到 b 在 hprof 文件中。

但是注意hprof文件是一个文件。它不是内存。它由检查其所有 Activity 内存位置的 JVM 生成,并生成对象的快照。

I guess there's code to maintain it, too?

有创建 hprof 文件的代码。它是 JVM 的一部分。

Does it have anything to do with object headers?

有点像。生成 hprof 文件的代码理解对象 header 。

Where do the actual references exist?

在内存中;见上文。

If not, where did the hprof file come from?

hprof 文件由 JVM 或与 JVM 对话的工具编写。 (我不是 100% 确定哪个,但这并不重要。)

关于java - 对 Java 对象的引用真正存在于何处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57704607/

相关文章:

java - Java中如何查找一个对象的所有引用者?

java - 如何通过忽略大小写来过滤 Recycleview?

java - 调用 RxJava 的 Throttle 方法

android - 未收到扫描结果

Java环境变量,CLASSPATH与CLASS_PATH?

java - 为什么 Eclipse 代码格式化程序会在 Javadoc @see 标记中中断 </a>?

java - 如何在Java中将Elasticsearch聚合的结果打印为JSON字符串?

安卓 + Wowza + RTSP。玩的不错,但是无法控制MediaController

tomcat - Tomcat 中的 Alfresco : OutOfMemory

jvm - 如何使用多个 Java 代理启动我的 Java 程序?