It's easy to leave memory leaks, especially when static variables are involved, and especially-especially when dealing with UI-related things (where a bitmap could hold a reference to its view and vice versa). Romain wrote an article about that a while ago.
That said, I'm not tempted to actually use System.exit() in my app because some smartass users gave me one-star ratings after they looked at a process viewer and found out that my app is still running (it starts on boot to set up a notification if necessary, so it pretty much always shows up in a process viewer). Of course, they didn't check "top" to see if it actually eats up any CPU power, and of course it doesn't, but they're handing out one-star ratings anyway, so I figure the only way is to quit the app in code. -Mike On Apr 29, 2:56 am, quakeboy <[email protected]> wrote: > @Sudha > > Hey I have been through the same. I frankly don't believe in what > these guys say. No offense here guys but I have experimented myself. > Basically the GC is not good. > > I was using xml for game menus. My game was having this problem for a > long time. Finally I removed all the @drawable/<picname> from the xml > layout files. I used many background images, image views for buttons > with images that change on touch etc.. > > I loaded all of them using BitmapFactory.decodeResource and then > cleaned up using bitmap.recycle() when needed, finally game never > crashed anymore. It was like I was coding C++ again :) I know its > tough to change everything, but it was worth it. > > I did the cleanup properly too by handling the activity lifecycle. and > even set everything to null and called System.gc when pressing the > exit button. > > One more thing, when I clickedquitin my app. I set the contentview > to an empty layout and then nulled everything and called gc and > recycles bitmaps. Finally all crashes disappeared. Otherwise every > second time I start my game it would crash. > > Hope this helped.. > > On Apr 28, 6:31 pm, Jean-Baptiste Queru <[email protected]> wrote: > > > Write your code such that it either cleans up those static variables > > or re-uses them if they've already been initialized. > > > There are going to be many combinations of the lifecycle of your > > activity that will be similar to what you're seeing (e.g. your app > > going in the background, the phone getting locked, the orientation > > changing), and you'll need to deal with the problem at its root. > > You're attacking a symptom without attacking the root cause. > > > JBQ > > > On Tue, Apr 28, 2009 at 6:24 AM, Sudha <[email protected]> wrote: > > > > I could leave the process to OS to kill but if I want to launch it > > > again in no time i get exceptions as the memory allocated previously > > > is not being erased. > > > > I am handling all the activities in the wrapper correctly but the > > > problem seems to be: > > > > I have most of the references created and assigned to static variables > > > > I mean all the instances of the objects are being referenced by static > > > variables, so might be all the variables are still hiding in the > > > memory even after the app has exited. > > > > is there any other way to kill the process when finish() is called...? > > > > On Apr 28, 6:10 pm, Jean-Baptiste Queru <[email protected]> wrote: > > >> This is not the way Android works. > > > >> JBQ > > > >> On Tue, Apr 28, 2009 at 5:56 AM, Sudha <[email protected]> wrote: > > > >> > So can you please just brief me on where to concentrate and what all > > >> > should be done while closing an app so that it is entirely erased from > > >> > the memory when exited...? > > > >> > On Apr 28, 5:51 pm, Jean-Baptiste Queru <[email protected]> wrote: > > >> >> finish() doesn't close yourapplication, is just closes your activity. > > >> >> The Appliction object itself stays behind, as well, as the entire > > >> >> process, as long as there's memory available to keep them around, so > > >> >> that re-launching your app is faster then next time around. > > > >> >> JBQ > > > >> >> On Tue, Apr 28, 2009 at 5:40 AM, Sudha <[email protected]> wrote: > > > >> >> > Hi, > > > >> >> > I have been developing a game on Android and wrote a wrapper for > > >> >> > J2ME > > >> >> > classes, > > > >> >> > When notifyDestroyed() is called in my ME program and calling > > >> >> > finish() > > >> >> > but theapplicationdoesn't close correctly. > > > >> >> > The App goes to background and when launched again it shows an error > > >> >> > message and presents an option to "force close" the App, if i force > > >> >> > close it and launch again, the app launches fine but again the same > > >> >> > has to be repeated upon every launch.. > > > >> >> > Can you please explain why the App is not being erased from memory > > >> >> > when finish() is called.\ > > > >> >> > when i check the log i found no exceptions when closing but when > > >> >> > launched again it throws a null pointer exception. > > > >> >> > for now to work around I placed "System.exit(0)" after calling > > >> >> > finish > > >> >> > () so that the app is exited abruptly, but am waiting for a valid > > >> >> > answer on whats going on behind...? > > > >> >> -- > > >> >> Jean-Baptiste M. "JBQ" Queru > > >> >> Android Engineer, Google. > > > >> >> Questions sent directly to me that have no reason for being private > > >> >> will likely get ignored or forwarded to a public forum with no further > > >> >> warning. > > > >> -- > > >> Jean-Baptiste M. "JBQ" Queru > > >> Android Engineer, Google. > > > >> Questions sent directly to me that have no reason for being private > > >> will likely get ignored or forwarded to a public forum with no further > > >> warning. > > > -- > > Jean-Baptiste M. "JBQ" Queru > > Android Engineer, Google. > > > Questions sent directly to me that have no reason for being private > > will likely get ignored or forwarded to a public forum with no further > > warning. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

