Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid memory leak between activities
    primarykey
    data
    text
    <p>I'm trying to pinpoint this memory leak.</p> <p>I have two <code>SurfaceViews</code>, <code>A</code> and <code>B</code>. I start <code>A</code>, then navigate to <code>B</code>, then press the back button to go back to <code>A</code>, and then I navigate to <code>B</code> again.</p> <p>I can see my allocated memory rise each time I do this, and eventually I'll get an out of memory error.</p> <p>Here is how I navigate to <code>B</code>, from inside the <code>SurfaceView</code> connected to <code>A</code></p> <pre><code> Context context = this.getContext(); Intent i =new Intent(context, StartCareer.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(i); </code></pre> <p>In both views, I have a lot of Bitmaps drawing. In <code>B</code>, I can't find any references to <code>A</code>, and the only reference outside the context that I can think of is a reference to a Global class that I have. I also have some analytics stuff going on in the background. It could be a million different things, I'd imagine</p> <p>I have the DDMS view on Eclipse up, but I'm not sure what I'm looking at, or how to find the exact object that keeps getting repeated.</p> <p>I'd accept either a crash-course/tutorial on the DDMS Allocation Tracker, or someone to point out what I'm doing wrong.</p> <hr> <p>Additional information:</p> <p>I have some bitmaps being drawn on a <code>SurfaceView</code>. Examples of such from <code>B</code> are:</p> <pre><code>////At class level Bitmap rightB,leftB; ////In the constructor rightB = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.right), 100,75, true); ////In doDraw canvas.drawBitmap(rightB, rbX, rbY, null); </code></pre> <p>And my onDestroys</p> <pre><code>@Override public void surfaceDestroyed(SurfaceHolder holder) { if (mThread.isAlive()){ mThread.setMenuRunning(false); } } </code></pre> <hr> <p>So I've run MAT and found one leak, at least. My <code>Thread</code> Keeps getting recreated. Here's what's doing it. </p> <pre><code>@Override public void surfaceCreated(SurfaceHolder holder) { loading=false; if (!mThread.isAlive()){ mThread = new ViewThread(this); mThread.setMenuRunning(true); mThread.start(); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { if (mThread.isAlive()){ mThread.setMenuRunning(false); } } </code></pre> <p>Assuming that these methods get called every time the view loses or gains focus, this seems obviously wrong. How can I re-organize this so that it's not? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload