Question

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?

Was it helpful?

Solution

When the phone configuration changes(like screen rotation), new activity created and dalvik heap get increased

A new activity is created. That may or may not increase the size of the heap. The heap size is only increased if you are getting close to the heap size limit (and the heap can be expanded).

If you watch that video, you will learn how to use MAT to really determine memory leaks, rather than relying upon LogCat messages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top