Problem releasing activities

by Joan Pujol » Fri, 28 Jan 2011 06:26:15 GMT

Sponsored Links
 've an application that has a service that updates some widgets and
also has some normal foreground activities to let the user view some
My problem is that I discovered [1] that my application consumes a lot
of memory. That memory is mainly consumed by the activities, and the
big problem is that I'm not been able to release the memory of the
activities once they are started.

I've look at various articles about memory leaks and I've tried to
don't retain activity contexts.
I've tried to put a finish() in onPause() of activity to try to force
to release
I've tried to analyze with MAT with dominator tree but it doesn't
shows any class of my app as a dominator.
Also I've tried to analyze one of the activities with MAT, but I don't
see why memory is retained. Here is an extract of ingoing references
to one of the activities:
It seems that all of this references are from the view, or is one of
them suspicious?

| Shallow Heap | Retained Heap
cat.joanpujol.eltemps.PredictionActivity @
0x482b70e0 | 192 | 16.304
|- mContext android.widget.ToggleButton @
0x48195bf8 | 536 | 2.800
|- mContext$DecorView @
0x4819f4b8 | 368 | 696
|- mContext @
0x481a5dc0 | 32 | 56
|- mContext @
0x481a5e08 | 32 | 88
|- [0] java.lang.Object[2] @
0x481a5e30 | 24
| 56
|- mContext android.widget.ScrollView @
0x481b3cc8 | 384 |
|- mCallback, mContext @
0x481c74c8| 176 | 2.320
|- mContext android.widget.FrameLayout @
0x481ce8a8 | 328 | 648
|- mContext android.widget.LinearLayout @
0x481d66a0 | 328 | 5.112
|- referent java.lang.ref.WeakReference @
0x481ef528 | 24 | 24
|- activity$LocalActivityRecord @
0x48226cc0 | 48 | 48
|- mOuterContext @
0x4827ee48 | 152 | 320
|- mContext android.widget.ToggleButton @
0x4828f3a0 | 536 | 2.808
|- mContext android.widget.TextView @
0x48292838 | 504 |
|- mContext android.widget.LinearLayout @
0x4829b620 | 328 | 584
|- mContext android.widget.ToggleButton @
0x482b54e0 | 536 | 2.808
|- mContext android.widget.ImageView @
0x482ca830 | 312 |
'- Total: 17
| |

Some one can give me some ligth?
I'm doing something bad?
Any information or suggerence will be very apreciated.

A lot of thanks in advance,


Re: Problem releasing activities

by JAlexoid (Aleksandr Panzin) » Sat, 29 Jan 2011 00:06:35 GMT

 ry getting the phone memory filed up. So it starts GC'ing and killing
off processes to release the memory. Or try filling up the heap with
total garbage and trigger a GC.
If after that point you actually have the unused(or what you would
expect to become garbage) Activities and Views retained, then you have
a leak.

High mem usage does not mean that there is a leak, by itself.

And to have a low mem usage, you need to carefully create new objects
and hold on to them for a long time. That goes also for Strings,
resources and goes double for Bitmaps.

On 28 , 00:26, Joan Pujol <> wrote:


Sponsored Links

Other Threads

1. GridView is not coming in center of parent

I am using following to display gridview of images :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="



But it is giving display left side with center_ vertical,

I used android:layout_centerHorizontal="true" also to bring grid view
in to horizantal center , then also it is giving left side of parent
with center_ vertical,

   I want to display grid view in center(vertical as wel as hori in
parent OR if this not possible then Cente_hori);
   I tried all but for any options but it either gives top_left  of
parent or
either left_with_vertical_center.

Whats the matter will some body clear me.


2. Fwd: Working of locationListener() in real time on device?

Kindly look into this query........


---------- Forwarded message ----------
From: sheik <>
Date: Feb 12, 3:05pm
Subject: Working of locationListener() in real time on device?
To: Android Developers

i need to know about the LocationListener() working in therealtime...

Does it expect the user(device) to move in order to update the
current location details or it automatically updates when ever the gps
is enabled?

Another query is regarding the getLastKnownLocation().....

When is that last known location will be lost and thus returns null...
(in realtime)...



3. Android Conference in Bangalore

4. Problem in going in back/previous activity

5. Android Screen Size Question

6. How to cancel a notification?

7. How to get uncompressed sound(uncompressed MP3) data in Android framework