Re: [android-developers] Re: bitmap.recycle() and multiple passes through a method question
On Thu, Apr 19, 2012 at 03:15:23PM -0700, Streets Of Boston wrote: > 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: No worries. This was before I read your explanation (that I just commented on and thanked you for). I understand now. :-) Thanks, --jim -- THE SCORE: ME: 2 CANCER: 0 73 DE N5IAL (/4)| Peter da Silva: No, try "rm -rf /" spooky1...@gmail.com| Dave Aronson:As your life flashes before < Running FreeBSD 7.0 > | your eyes, in the unit of time known as an ICBM / Hurricane: | ohnosecond (alt.sysadmin.recovery) 30.44406N 86.59909W | 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
Re: [android-developers] Re: bitmap.recycle() and multiple passes through a method question
" *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
Re: [android-developers] Re: bitmap.recycle() and multiple passes through a method question
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
[android-developers] Re: bitmap.recycle() and multiple passes through a method question
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. 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. On Thursday, April 19, 2012 9:11:01 AM UTC-4, Spooky wrote: > > Re-stating (in clearer terms...I think) one remaining question (I think > I have my answer for the rest---we'll see). > > Let's say I have a method which is used frequently to do some work on > bitmaps. If, during that method, I create a temporary bitmap, and then > recycle it, and don't touch it for the remainder of the time in that > pass through that method, but then use it again (and recycle it again) > in anoother pass through that same method, does that then attempt to > re-use the bitmap I recycled in the previous pass? Or is a new copy > created and recycled in each pass? > > And, along with that, once I leave that method, and the temporary > bitmap that's local to that method has not been recycled, is its > memory freed up? Or does it continue to chew up memory? > > Thanks, >--jim > > -- > THE SCORE: ME: 2 CANCER: 0 > 73 DE N5IAL (/4)MiSTie #49997 < Running FreeBSD 7.0 > > spooky1...@gmail.com ICBM/Hurricane: 30.44406N 86.59909W > > "'Wrong' is one of those concepts that depends on witnesses." > --Catbert: Evil Director of Human Resources (Dilbert, 05Nov09) > > 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