Android : Activity Lifecycle Cause Memory Leaking

Aug 7, 2009

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?

Android : Activity Lifecycle Cause Memory Leaking


Android :: ClassLoader Leaking Memory?

Dec 17, 2009

I have a ClassLoader in Activity's onCreate which loads a specific class from a library, and is working fine, except that when activity is destroyed, the memory resources about the loaded class are not released.If the same activity gets created multiple times very quickly (by launching it, and destroying it by pressing the Back button), and the process doesn't happen to be killed by Android yet, the memory usage of the corresponding process grows continuously until the app crashes,and process dies.The problem is that this happens even if no objects are instantiated using the loaded class. There seems a problem with garbage collector, which doesn't seem to release resources about the loaded class on Destroy even if there are no references to it.If android would have killed the process right away when the last activity of the process gets finished, there wouldn't be a problem, but this is managed by Android system, and it doesn't always kill the process right away. A workaround may be to kill the process explicitly on destroy, but this is not encouraged way to do, as Android is supposed to manage the process.

An alternative is to have a functionality that allows a class to be unloaded onDestroy, but this doesn't exist. By design, the garbage collector is supposed to take care of this.Is there a solution regarding this?

View 8 Replies View Related

Android : ActivityThread.ContextCleanupI­nfo Leaking Memory

Dec 16, 2009

I'm trying to locate a memory leak in my app (it's client for a mediacenter). So I start it up, go to the screen that lists all movies, go back to my home activity, trigger the GC a few times manually via DDMS, dump the memory heap, pull it, convert it and load it into MIT in Eclipse.

Now the movie list screen is pretty heavy, around 800k of movie objects, which should be freed when I go back to the home screen. However, it stays allocated, with the GC root as a local variable in the main thread at ActivityThread.ContextCleanupInfo (see attached screenshot).

I've tried searching but there is no documentation on this class, not even in the source code. Is there any way to avoid this kind of behavior? Am I doing something wrong or is the problem in Android? My app is open source and can be checked out here[1]. http://code.google.com/p/android-xbmcremote/

View 4 Replies View Related

Android : Debugging Memory Leaking - Program

Mar 31, 2009

What would be the best way to debug a leaking program?

I have developed a media player (includes a background service doing the playing, and a UI, and I access getResources(), MediaStore and things like this often).

Whenever I rotate the screen or reenter the app the total memory allocated to my process grows some 70 to 100KB. After some 6-10 rotations it is dead due to an out of memory exception.

In the meantime I have removed every static modifier to global vars, added an onDestroy function that unregisters the intents and service connection (and even puts every global var to null again :P), but still the program memory grows... and dies after a few rotations.

Given the situation I even made the program stop right after just calling setContentView, and still the memory leaks:

CODE:......................

View 3 Replies View Related

Android : Simple ListView App Is Leaking Memory

Nov 18, 2010

I created a simple app with a ListView following the ListActivity examples I found on the net.

The app has 2 activities with the first having a button to create the second. When i hit the close button on the second activity I would like it to release its memory (or at least allow it to be garbage collected).

Currently it will never release.

I must be doing something wrong here because the MyListActivity never gets released. Can anyone tell me if I am doing something wrong with the way my activities are created/destroyed? or if my usage of the ListView is wrong?

My App as a zip - http://www.mediafire.com/?l26o5hz2bmbwk6j

Screen Shot of Eclipse MAT showing the list activity never releasing memory - www.mediafire.com/?qr6ga0k

View 1 Replies View Related

Android :: Find Exact Place Of Memory Leaking?

Oct 23, 2009

can anyone tell me any solution or tool provided by Android to find the exact place of memory leaking?

View 2 Replies View Related

Android :: Leads To Theorize That Memory Is Leaking On The Stack

May 7, 2010

I'm writing an app that has a foreground service, content provider, and a Activity front end that binds to the service and gets back a List of objects using AIDL. The service does work and updates a database.

If I leave the activity open for 4-8+ hours, and go to the "Running Services" section under settings on the phone (Nexus One) an unusually large amount of memory being used is shown (~42MB).

I figure there is a leak. When I check the heap memory i get Heap size:~18MB, ~2MB allocated, ~16MB free. Analyzing the hprof in Eclipse MAT seems fine, which leads me to theorize that memory is leaking on the stack. Is this even possible? If it is, what can I do to stop or investigate the leak? Is the reported memory usage on the "Running Services" section of android even correct (I assume it is)?

Another note: I have been unable to reproduce this issue when the UI is not up (with only the service running)

View 1 Replies View Related

Android :: Activity Lifecycle OnStart OnStop Possible?

Oct 5, 2010

In the Android Application Fundamentals it says that after the call to the onStart()-method of the activity lifecycle either the callback method Resume() or onStop() is called. In case of an "normal" Start of an activity the system calls onCreate(), onStart(), onResume().But does somebody know an example where onStart() - onStop() are executed one after another?

View 2 Replies View Related

Android :: Activity Lifecycle And Static Variables

Jul 14, 2009

I just ran into a situation where it looks like a static variable reference is persisted across activity sessions. I didn't expect that because I thought that when an activity exits, it's de-referenced and garbage collected. I am wondering if anyone can shed some (more) light on when the VM eliminates object references for Activities and Services and in particular when static variables get reset to default values?

View 7 Replies View Related

Android :: Activity Lifecycle On Nexus One - OnStop Not Called

Mar 4, 2010

I have a problem with the activity lifecycle specifically on Nexus One (2.1 running on emulator works fine). If I just create a simple empty Activity with no special launchModes that logs the calls on the onStart and onStop methods, this is what I see: - launch app: onStart called; - home button: onStop NOT called; - launch app: onStart NOT called; - home button: onStop NOT called: and so on. Sometimes if I press the back button then the onStop is not called, but the when i launch the activity again the onStart is called and right after the onStop is called. Similar results with different launchModes. What is going on? Can anyone confirm this?
i found an android issue for the problem here: http://code.google.com/p/android/issues/detail?id=6094 and a similar thread here http://groups.google.com/group/android-developers/browse_thread/threa.

View 24 Replies View Related

Android :: Rule That Relates OnMeasure To The Activity Lifecycle

Jul 12, 2010

I have a custom view on which I need to call a method from my activity after the view has been measured in onMeasure. I would like to know exactly when onMeasure is called in the View layout process. It looks like onMeasure is called after my activity´s onCreate, onStart, and onResume. I could override onMeasure and maintain a variable that contains whether the view has been measured or not. However it would be nice to know if there is a rule that relates onMeasure to the activity lifecycle?

View 4 Replies View Related

Android :: Using Activity Lifecycle Methods / What's Best Strategy For Binding?

Sep 15, 2010

I'm binding to a local Service (that is, not using IPC and AIDL) from several activities. I want to ensure that I'm not holding references to this service from activities that the user isn't using. My options are: 1.) to bind to the service in onCreate() and unbind in onDestroy(). 2.) bind in onStart() and unbind in onStop(). 3.) bind in onResume() and unbind in `onPause(). Or some combination of these. Which is the best-practice way of binding and unbinding to a local service? Do I not need to be concerned with holding local connections from stopped activities? Additionally, once bound to this particular service I am retrieving a Cursor which is attached to my ListActivity via a CursorAdapter. The data retrieved by the Cursor may have changed while the Activity was out of view so I want to requery it when the Activity is shown again. If I bind in onCreate() I can requery in onRestart(). If I bind in onResume() each time the data will be fresh because I'll query it in the Service's connected callback.

View 1 Replies View Related

Android :: How To Handle Activity Lifecycle On Wake Up - Alarm App

Oct 4, 2010

I'm having a couple of problems with an alarm app I am developing.

The first thing that I think is a bit weird is that when an alarm goes of and wakes the phone up. These things happend.

oncreate
onresume
onpause
onresume

Why are they run in that order? The last two should not be called? And this is what's causes me big trouble, because when i press home or back on the phone, onPause is run, which I want to call finish() from. And that part works as it should, but that does not work when the phone wakes upp from sleep bacause of the onPause call...

View 2 Replies View Related

Android :: Get Information Of Activity Lifecycle Callbacks In Views Drawn?

Aug 3, 2010

I want to get the size of a view that is in my activity but I am not able to get that information in any of the activity lifecycle callbacks (onCreate, onStart, onResume). I'm assuming this is because the views have not been drawn yet. At what point are views drawn and is there a callback I can put my code so I can get the size of the view?

View 2 Replies View Related

Android :: Activity / Process Lifecycle - Save / Load Data To / From Disk

Nov 26, 2009

My app is made of two activities, A and B. I'm considering this sequence of steps: Activity A is started. A launches B [A is paused, B is running]. B launches a map intent [A and B are both paused now]. Now the user is using the maps application and the system decides it needs more memory. Can the system kill only one of my activities for memory, or will it always kill all activities in a "process" in this situation?

Both activities share some static data like:

class Data {
public static String mName;
public void save() {
// write to file: mName;...................

View 1 Replies View Related

View Lifecycle And Refresh When Returning From Activity?

Oct 26, 2012

I'm writing an application for Android and have multiple Activities, there are three to be exact. When a user drills down to the record they would like to view, they can modify it.

The issues is that when I click the back button to move to the previous screen, i'd like to refresh it to reflect the update performed by the end user. I can't figure out how to hook onto the appropriate event and then refresh my data on that view.

View 3 Replies View Related

Android :: Detailed Android Activity Lifecycle - OnAttachedToWindow()

Jun 14, 2010

I'm interested in android activity lifecycle and I would like to get more detailed description/documentation/reference than widely available basic (onCreate->onStart->onResume) one.

My need comes from realizing that starting new activity (Theme.Dialog styled) from onAttachedToWindow() greatly improves response time if comparing to starting it from onCreate(). I wonder how this onAttachedToWindow() fits into whole android activity lifecycle. Official API ref description "Called when the window has been attached to the window manager" doesn't help a lot.

View 1 Replies View Related

Android : Leaking Bitmaps From Adapter's GetView

Mar 31, 2009

I definitely have a memory leak problem and i'm trying to figure out there. After 6-10 config changes i'm getting out of memory in regards to BitmapFactory. I'm kind of suspect that this is going on within adapter. I have a listview . ListItems are an thumbnail image ( ImageView ) and TextView for text.

Here is the getView code.

CODE:..................

And get ThumbnailBitmap() is basically BitmapFactory.decodeByteArray ..

Is it possible that i'm leaking drawables ? Heap is not increasing by the way .

View 3 Replies View Related

Android : Avoid Leaking Context In ArrayAdapter

Sep 28, 2010

I read the Avoiding Memory Leaks article with interest, and am concerned about danging references to the context object. I have a class like the following.

CODE:.........

Is it a problem to have a reference to a LayoutInflater object, since it must be using the context object somehow? Is there a better design pattern for what I'm trying to do here? (Use the context only to initially inflate the XML; from then on just use the View that's passed in to getView)

View 1 Replies View Related

Android :: How To Find Where Memory Leaks In Activity?

May 20, 2010

When start Activity A, I found the memory usage of application is about 5MB. Then start Activity B from A via startActivity. In Activity B, I created a thread, and traverse file system in this thread, after traversing completed, call finish() and to return to Activity A. At this time, I found the memory usage of application is about 8MB (GC is forced before check memory usage). How to find Where memory leaks? By the way, I checked the memory usage with DDMS.

View 5 Replies View Related

Android :: Memory Leak In Activity - Reclaiming

Sep 24, 2009

In my app activity A creates activity B, however when the back key is pressed it goes back to activity A. This is a simplified version of my application. I would expect memory to be reclaimed when going back to Activity A. Going to activity B allocates more memory. I am using dumpsys meminfo to get the allocated kbs. How can I easily tell what memory is creeping? I do not keep any references to activity B. I know about the ddms allocation tracker, but wondering if there is a more better tool to figure this out.

View 2 Replies View Related

Android :: Activity Objects In Memory After On Destroy

Aug 3, 2009

I have a activity MyActivity, which "kills" yourself using the finish () method. The problem is: after the kill operation, method onDestroy is called, but the object of type MyActivity is never garbage-collected (I forced the GC run). It is causing a memory leak, because MyActivity is launched many times, by other activities. Does anyone know when the Activity object is supposed to be garbage- collected, and what can be done to avoid the issue I mentioned?

View 2 Replies View Related

Android :: Application - Activity's Memory Management

Mar 1, 2010

I have a problem with my application, and it's about a Virtual memory error: ERROR/AndroidRuntime(19790): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

The story is like this: I have an activity (let's call it A), the user click on a button from this activity, then i will make an api call somewhere in the internet, and after the result is back i start a subactivity (let's call it B).

In the activity B i have to dinamicaly load some images from the resources folder. I load the images into bitmaps -> drawables -> imageviews. After the user click's on some buttons i have to setResult(..), finish(), and get back to activity A.

The thing is that, goes from activity A to B, then B -> A, then A -> B for a few times, my app crashes with the message above: it doesn't have enough memory to load the interface.

I can not maintain the activity B on the stack because i don't want the user to go to this activity without going through activity A first.

View 2 Replies View Related

Android :: Free Up Memory By Finishing An Activity After Calling Another?

Feb 25, 2010

Hopefully the title wasn't to confusing but what I meant was the following:

Lets say activity A starts activity B by calling:

Intent myIntent = new Intent(Activity_A.this, Activity_B.class);
Activity_A.this.startActivity(myIntent);


Could I save/free up some memory by finishing Activity_A after Activity_B is begun (if thats even possible). Maybe through the following:

Intent myIntent = new Intent(Activity_A.this, Activity_B.class);
Activity_A.this.startActivity(myIntent);
Activity_A.finish();


Or would Acitivty_A call startActivity() and wait for Activity_B to finish before it called finish()?

The idea would then be that when the users end with Activity_B, it would just restart Acitivity_A (and finish itself in a similar fashion)? Would this create too much overhead? Thanks for any answers and I apologize if the formatting of this post isn't correct.

View 2 Replies View Related

Android :: Tell How Close Activity Is To Reaching Its Memory Limit

Oct 15, 2010

I'm writing a graphic design application for Android where the user can add several images to a document, where each image is stored as a Bitmap object. Each bitmap has roughly a dimension of 800x400 pixels and uses ARGB8888 pixel format (i.e. ~1.5Mb each).

I'm aware that most of the first generation Android devices have a 16Mb heap limit and this limit is 24Mb and larger for newer phones. I'm also aware that bitmap memory is allocated externally, but I'm confused and what the implications of this is.

My question is: How can I tell at runtime when adding a new Bitmap will get me too close to the memory limit?

Before someone suggests "don't use that much memory", I know that one option I have is to limit how many Bitmaps the user can create such that I know this limit is safe for the most basic Android phones. However, I'd like for phones with a bigger memory limit to support more bitmaps and/or bigger bitmaps.

I know to check for OutOfMemory exceptions when allocating bitmaps. However, there will be some situations where I've only got just enough memory left to allocate one more bitmap. After this point, the whole application will be unstable because even allocating small things like strings could cause an OutOfMemory exception. This is something I want to avoid.

I'm not sure how to define "too close to the memory limit", but I suspect something like "don't allocate more than half of your available memory to bitmaps" would work OK as my other data structures I store in memory are small in comparison.

View 3 Replies View Related

Android :: Low Memory Cause Activity.getIntent() To Return Null?

Sep 10, 2009

As the title says? Or what situations can cause this method to return null? I would of thought it retained this object always.

View 2 Replies View Related

Android :: Simulate Killing Activity To Conserve Memory?

Mar 1, 2010

Android doc say:"When the system, rather than the user, shuts down an activity to conserve memory, ... "
But how to simulate this situation?I want to debug the onRestoreInstanceState method,but don't know how to.

View 2 Replies View Related

Android :: Simple Frame Animation - Memory Leak Activity

Apr 14, 2010

I am using a simple frame animation and when I exit and reenter my activity the activity is still referenced in memory.

//This is a sample activity I created to simulate the problem public class MemoryLeakActivity extends Activity {
@Override public void onCreate(final Bundle savedInstanceState) super.onCreate(savedInstanceState);
} @Override public boolean onKeyDown(final int keyCode, final KeyEvent event) {
final Intent i = new Intent(MemoryLeakActivity.this, LeakyActivy.class);
startActivity(i); return super.onKeyDown(keyCode, event);
} }

View 3 Replies View Related

Android :: Force RecognizerIntent Activity To Stay Cached/in Memory

Feb 16, 2010

I was wondering if it is possible to force the RecognizerIntent Activity (or any other Activity) to stay cached so that the launch time would be faster.

View 2 Replies View Related

Android :: Way To Visualize Activity Stack (activities In Memory) On Droid?

Jun 26, 2010

I'm currently debugging my app which is quite complex and has up to 5 activity levels. In order to detect memory leaks (i.e. activities that aren't removed from memory even finish() is called, due to some references held somewhere) I want to check which activities are still alive in memory. Currently I create hprof dumps, but it's not very convenient, cause every time I need to mount the sdcard, copy the hprof dump file from the sdcard to my PC, etc. (Side note: I already tried to automate the pulling of my hprof file more easily, but I'm on an unrooted device and adb pull <hprof file> won't let me / no permission.) Therefore I am wondering, if all I want to know is IF and WHICH activities are still currently alive in my memory, is there a way through the Android API or any other way on-the-fly with which I can achieve this (list all alive activities of my app), programatically.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved