title: Occur Memory Leak, when create object using 'new' on android
body: <p>recently I work reducing memory leak on my android source.</p>
  
  <p>I use allocation tracking tool on android studio</p>
  
  <p>my app is recording camera preview app</p>
  
  <p><a href="https://i.stack.imgur.com/N00yL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N00yL.png" alt="enter image description here"></a></p>
  
  <p>if you look at the picture </p>
  
  <pre><code>protected int getOutPutBufferIndex() {
         IMediaCodec.BufferInfo bufferInfo = new IMediaCodec.BufferInfo(); //here occur memory leak
         int outputBufferIndex = mediaCodec.dequeueOutputBuffer(bufferInfo, timeout); //get buffer index
         return outputBufferIndex;
  }
  </code></pre>
  
  <p>this method only return buffer index.</p>
  
  <p>I guess  occur memory leak when create object using <code>new</code> </p>
  
  <p>so I try add <code>bufferInfo = null;</code> on <code>return outputBufferIndex;</code> </p>
  
  <p>but <code>bufferInfo = null;</code> the assigned to never used message.</p>
  
  <p>and occur memory leak unchanged.</p>
  
  <p>so, How to when create object using <code>new</code> , avoid memory leak on android?</p>
  
  <p>thanks.</p>