本文介绍了Android:浅堆和保留堆之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过MAT找出应用程序的内存泄漏,在list_object中我找到了一些数值 int Shallow heapretained heap列.这些值是什么,以及如何知道内存泄漏在哪里.

I trying to find out memory leak of app by MAT, Here In list_object I found some numeric value int Shallow heap and retained heap column. What is these value, and how to know where is memory leak.

推荐答案

来自 Nikita Salnikov -Tarnovski的博客:

从许多方面来说,保留堆都更有趣.只有极少数 您对浅堆感兴趣,在大多数情况下,您的实际问题是 可以翻译为如果我从内存中删除该对象, 现在垃圾回收器可以释放更多的内存."

The retained heap is in many ways more interesting. Only rarely are you interested in the shallow heap, in most cases your actual question can be translated to "If I remove this object from the memory, how much memory can now be freed by the garbage collector".

现在,众所周知,所有Java垃圾回收(GC)算法 请遵循以下逻辑:

Now, as we all remember, all Java garbage collection (GC) algorithms follow this logic:

1)有些对象被GC视为重要". 这些被称为GC根,并且(几乎)从不丢弃.他们是, 例如,当前正在执行的方法的局部变量和输入 参数,应用程序线程,来自本机代码的引用和 类似的全局"对象.

1)There are some objects which are considered "important" by the GC. These are called GC roots and are (almost) never discarded. They are, for example, currently executing method’s local variables and input parameters, application threads, references from native code and similar "global" objects.

2)假定从这些GC根引用的任何对象都在使用中 因此,不会被GC丢弃.一个对象可以引用另一个对象 Java中的不同方式,在最常见的情况下,存储对象A 在对象B的字段中.在这种情况下,我们说"B引用A".

2)Any objects referenced from those GC roots are assumed to be in use and hence not discarded by the GC. One object can reference another in different ways in Java, in the most common case an object A is stored in a field of an object B. In such case we say "B references A".

3)重复此过程,直到所有可以传递的对象为止 将访问从GC根目录到达的目录并将其标记为正在使用".

3)The process is repeated until all objects that can be transitively reached from GC roots are visited and marked as "in use".

4)其他所有未使用的东西都可以扔掉.

4)Everything else is unused and can be thrown away.

这篇关于Android:浅堆和保留堆之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 13:44