Hi! I noticed a memory leak in the GLSurfaceView tutorial (http://developer.android.com/resources/articles/glsurfaceview.html) Attached application leak overview (very simple):
1. Start TheLeakActivity via button press from LeakStarterActivity 2. TheLeakActivity uses the tutorial code to create a GLSurfaceView 3. When pressing the back-button TheLeakActivity is closed (but leaked) 4. Repeating 1-3 multiple times results in a OutOfMemoryException What's leaked: - Each TheLeakActivity (via some context in GLThread and/or EglHelper, verfied with MAT, see attached leaked.hprof) What i've tried so far - Verfied the leak on android 3.2 (Samsung galaxy tab plus) and 4.0.3 (Acer Iconia Tab A200) - Searched the internet for similar problems: nothing - Made sure to resume and pause the GLSurfaceView in order to allow the necessary housekeeping - Tried activity- and application-context - Verified in strict mode that multiple instances of TheLeakActivity remain alive Any Ideas how I should proceed? Could someone confirm that I'm not completely crazy? Greatly appreciate any help -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
package at.laborg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class LeakStarterActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void startLeakActivity(View view)
{
Intent intent = new Intent(this, TheLeakActivity.class);
startActivity(intent);
}
}package at.laborg;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
public class TheLeakActivity extends Activity
{
private static final String TAG = "TheLeakActivity";
private byte[] makeTheLeakCount = new byte[1024 * 1024];
private GLSurfaceView mGLView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectActivityLeaks().penaltyLog().build());
super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplicationContext());
mGLView.setRenderer(new ClearRenderer());
setContentView(mGLView);
}
@Override
protected void onPause()
{
Log.d(TAG,"onPause called");
super.onPause();
mGLView.onPause();
}
@Override
protected void onResume()
{
Log.d(TAG,"onResume called");
super.onResume();
mGLView.onResume();
}
}
class ClearRenderer implements GLSurfaceView.Renderer
{
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{}
public void onSurfaceChanged(GL10 gl, int w, int h)
{
gl.glViewport(0,0,w,h);
}
public void onDrawFrame(GL10 gl)
{
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
}
}
main.xml
Description: XML document
AndroidManifest.xml
Description: XML document

