0

After watching the video of Google I/O Memory Management, I come to know about the cause of memory leaks and how to check it by logcat. In one of the example mentioned in the video :

public class MainActivity extends Activity {

class Leaky {

    public void doSomething() {
        System.out.println("hello");
    } 
}

static Leaky leak = null; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (leak == null) {
        leak = new Leaky();
    }
    }
}

When the phone configuration changes(like screen rotation), new activity created and dalvik heap get increased. In this case logcat prints the increased dalvik heap size.

But when tested in Android 4.x device, not getting logcat related to increased dalvik heap size.

Did I miss something?

4

1 回答 1

3

当手机配置发生变化(如屏幕旋转)时,创建的新活动和 dalvik 堆会增加

创建了一个新活动。这可能会也可能不会增加堆的大小。仅当您接近堆大小限制时才会增加堆大小(并且可以扩展堆)。

如果您观看该视频,您将学习如何使用 MAT 来真正确定内存泄漏,而不是依赖 LogCat 消息。

于 2014-04-01T19:24:00.243 回答