3

I have this simple Android Studio project for testing out little code snippets. Today while I was fiddling around with some code, I noticed that each time I rotate my device, it causes the app to use more and more memory. Screenshot of the chart is as follows:

memory increase as I keep rotating the device

Each time I rotate the device, allocated memory increases and free memory amount decreases. When free memory hits zero, it cleans a chunk of memory, but not all. As I keep rotating device back and forth, eventually it causes more free memory made available to the app, and allocated memory keeps increasing and increasing.

This is a simple app with only single TextView and no execution code at all. No database activity, no network activity, no cursor, nothing to cause any memory leak whatsoever.

Here is the MainActivity.java content:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }
}

I tried to dump the java heap, but it looks all jibberish to me.

So is this the expected behavior? What is actually filling up the memory? What is going on?

SercioSoydanov
  • 980
  • 10
  • 29

1 Answers1

1

If that is your MainActivity then you don't have memory leaks.

But, if you want to be sure there is a button in the memory monitor called Initiate GB. Click it an it will run the Garbage Collector freeing up your unused references.

You will see that memory drops to its initial amount when doing that.

Juan Cruz Soler
  • 8,172
  • 5
  • 41
  • 44