" *Now, here's the question:  if I return to this method, and re-use the
locally-created bitmaps that are local to that method, is that considered
re-using a bitmap that's already been recycled?  Or is that a fresh chunk
of memory?* "

I don't quite understand it. If you create a bitmap local to a method, I 
assume that you mean that you create a bitmap that can only be referenced 
within that method:

public void someMethod() {
  Bitmap localBitmap = BitmapFactory.decode.....;
  ...
}

When you exit the method and you haven't assigned the reference of 
localBitmap to any other variable, then the Bitmap that is referred will be 
cleaned up by the garbage collector: The garbage collector will, at some 
point in time after you have returned from 'sometMethod', call the 
localBitmap.finalize() method. The finalize() method is implemented to call 
'recycle()'.

When you 'return' to someMethod(), I assume you mean you'll call 
someMethod()  again. If this is the case, then you'll create a brand-new 
Bitmap that will be assigned to localBitmap.

If you want the Bitmap, that is assigned to localBitmap, to survive after 
your code returns from someMethod, then you either need to assign 
localBitmap to a field (instance field or class field) or you need to 
return localBitmap as the return-value of someMethod(). 



On Thursday, April 19, 2012 9:49:23 AM UTC-4, Spooky wrote:
>
> On Thu, Apr 19, 2012 at 06:32:15AM -0700, Streets Of Boston wrote:
> > After you call bitmap.recycle(), you can no longer use that bitmap at 
> all. 
> > After calling recycle(), the bitmap still occupies a tiny little bit of 
> > memory in the DalvikVM. All its raw pixel data memory has been released, 
> > though. To release that tiny little bit of memory in the DalvikVM as 
> well, 
> > release the reference to the bitmap (e.g. by doing 'bitmap = null' or by 
> > just exiting the Java-block that contains 'bitmap' as a local variable) 
> and 
> > the garbage collector will clean it up later.
>
> Now, here's the question:  if I return to this method, and re-use the
> locally-created bitmaps that are local to that method, is that considered
> re-using a bitmap that's already been recycled?  Or is that a fresh chunk
> of memory?
>
> > When you don't call 'recycle()', the garbage collector will call 
> > 'recycle()' when the bitmap is garbage collected (through the bitmap's 
> > finalize() method). But since you can't control the garbage collector 
> > consistently across all types of devices/implementations, calling 
> > 'recycle()' yourself will make sure that the raw pixel data is released 
> at 
> > your convenience. 
>
> That definitely matches my understanding.  Cool.
>
> Thanks,
>    --jim
>
> -- 
> THE SCORE:  ME:  2  CANCER:  0
> 73 DE N5IAL (/4)        | DMR: So fsck was originally called
> spooky1...@gmail.com    |      something else.
> < Running FreeBSD 7.0 > | Q:   What was it called?
> ICBM / Hurricane:       | DMR: Well, the second letter was different.
>    30.44406N 86.59909W  |    -- Dennis M. Ritchie, Usenix, June 1998.
>
> Android Apps Listing at http://www.jstrack.org/barcodes.html
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to