[android-developers] Re: Activity Lifecycle Cause Memory Leaking

2009-08-20 Thread brian.schimmel

I experienced similar problems. Depending on how you navigate back to
your Activity, Android does not know that it should reuse the existing
instance and creates a new one. You can fix this easily with the
activities launch mode, which you set in the AndroidManifest.xml.
Setting it to singleInstance will ensure that there is only ever one
instance. Depending on your app this might have other disadvantages,
so you should check this part of the documentation:
http://developer.android.com/guide/topics/fundamentals.html#acttask

On 7 Aug., 07:23, efan e...@efansoftware.com wrote:
 Tested on both 1.5-R2 and R3, same result.

 On Aug 6, 10:22 pm, efan e...@efansoftware.com wrote:

 http://developer.android.com/reference/android/app/Activity.html

  The Activity Lifecycle could have implementation and or design bug:
  One case is to initialize a big image in onCreate(), try to reuse the
  image during the whole lifecycle, and then recycle the image in
  onDestroy().
  Test showed that onCreate() is called every time one navigate away
  from the activity and back again, but onDestroy() is not called at
  all. This behavour causes memory leaking for the big image (size
  960*1920). After 6+ times away and back to activity, the system runs
  out of memory and has tokillthe process.

  One workaround is to initialize the big image in onResume() and
  recycle in onPause(), but that's not so good reuse.

  Could it be better to change the process (as shown in the diagram) a
  little bit such as:
  Call onDestroy() first when a process is killed?


--~--~-~--~~~---~--~~
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: Activity Lifecycle Cause Memory Leaking

2009-08-06 Thread efan

Tested on both 1.5-R2 and R3, same result.

On Aug 6, 10:22 pm, efan e...@efansoftware.com wrote:
 http://developer.android.com/reference/android/app/Activity.html

 The Activity Lifecycle could have implementation and or design bug:
 One case is to initialize a big image in onCreate(), try to reuse the
 image during the whole lifecycle, and then recycle the image in
 onDestroy().
 Test showed that onCreate() is called every time one navigate away
 from the activity and back again, but onDestroy() is not called at
 all. This behavour causes memory leaking for the big image (size
 960*1920). After 6+ times away and back to activity, the system runs
 out of memory and has to kill the process.

 One workaround is to initialize the big image in onResume() and
 recycle in onPause(), but that's not so good reuse.

 Could it be better to change the process (as shown in the diagram) a
 little bit such as:
 Call onDestroy() first when a process is killed?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---