That looks fine. The only issue/trick for bitmaps that I'm aware of is the option to call bitmap.recycle(), which forces the bitmap to free its pixel memory immediately, rather than waiting for the GC. This is optional, since the GC will trigger this too. Calling recycle() is tricky, because now the bitmap object is "dead", and will throw an exception if it is used, so only do this if you're low on memory, and want to free some up right away (and you're SURE you won't reference that bitmap again).
On Dec 23, 2008, at 1:08 PM, Brad Gies wrote: I’ve seen many discussions on freeing Bitmaps, but I don’t think I have ever seen a definitive answer on the proper method of doing it. I have an activity which creates a custom class, and the custom class has a clear method, which I call before freeing the class. Below is the code from my custom class, and, and following it is the code from the OnDestroy event . Is this sufficient to make sure I am not leaking memory? Note that it is untested code right now, so may contain a few spelling mistakes. public class JSONDataTable { public ArrayList<Bitmap> BitmapArray; ….. Methods etc. …… public void Clear() { if (BitmapArray != null) { for (int i = BitmapArray.size() - 1; i > -1 ; i-- ) { BitmapArray.set(i, null); BitmapArray.remove(i); } } BitmapArray = null; } } FROM THE ACTIVITY protected void onDestroy() { if (JSONProductTable != null) { JSONProductTable.Clear(); JSONProductTable = null; } } Sincerely, Brad Gies ----------------------------------------------------------------- Brad Gies 27415 Greenfield Rd, # 2, Southfield, MI, USA 48076 ----------------------------------------------------------------- Moderation in everything, including abstinence --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---