I've got an app with 2 Activities. The first one launches on startup and with a button launches the second activity using an Intent.

Intent intent = new Intent(MainActivity.this, com.example.project.SomeActivity.class);
startActivityForResult(intent, 0);

In the second activity I have a camera and some memory allocation.

When I press the 'close' button in the second activity, I call Close on the camera and finish on the activity.

    m_camera.Close(CameraEnum.FRONT.getCameraID());
    this.finish();
    System.gc();

When I close the activity for the first time and call it back from the first activity all is good, also for the second time - but when I open it in the third time - I get an out of memory error on this line:

m_data = new byte[4*width*height];

The error I get is:

05-19 14:22:51.440: E/dalvikvm-heap(31838): Out of memory on a 1228816-byte allocation.
...
05-19 14:42:42.174: E/AndroidRuntime(7345): java.lang.OutOfMemoryError

I can find out why this should happen.

Any ideas?

Thanks!

有帮助吗?

解决方案

Well, found the problem - it really was a memory leak due to holding a reference to the 'Context' object. After releasing it - the app doesn't crash anymore.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top