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
data.
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?

Class
Name
| Shallow Heap | Retained Heap
---------------------------------------------------------------------------------------------------------------
cat.joanpujol.eltemps.PredictionActivity @
0x482b70e0 | 192 | 16.304
|- mContext android.widget.ToggleButton @
0x48195bf8 | 536 | 2.800
|- mContext com.android.internal.policy.impl.PhoneWindow$DecorView @
0x4819f4b8 | 368 | 696
|- mContext com.android.internal.policy.impl.PhoneLayoutInflater @
0x481a5dc0 | 32 | 56
|- mContext com.android.internal.policy.impl.PhoneLayoutInflater @
0x481a5e08 | 32 | 88
|- [0] java.lang.Object[2] @
0x481a5e30 | 24
| 56
|- mContext android.widget.ScrollView @
0x481b3cc8 | 384 |
1.392
|- mCallback, mContext com.android.internal.policy.impl.PhoneWindow @
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 android.app.LocalActivityManager$LocalActivityRecord @
0x48226cc0 | 48 | 48
|- mOuterContext android.app.ContextImpl @
0x4827ee48 | 152 | 320
|- mContext android.widget.ToggleButton @
0x4828f3a0 | 536 | 2.808
|- mContext android.widget.TextView @
0x48292838 | 504 |
3.880
|- mContext android.widget.LinearLayout @
0x4829b620 | 328 | 584
|- mContext android.widget.ToggleButton @
0x482b54e0 | 536 | 2.808
|- mContext android.widget.ImageView @
0x482ca830 | 312 |
720
'- Total: 17
entries
| |
---------------------------------------------------------------------------------------------------------------

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,



[1]
http://groups.google.com/group/android-developers/browse_thread/threa



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 <joanpu...@gmail.com> wrote:

--


Sponsored Links


Other Threads

1. KeyStore causing EOFException

I have some code for my app that creates a keystore in android,
creates some default keys then saves the keystore.

Later on the code tries to reload the keystore, on the emulator this
runs fine however when run on a phone I get an EOFException. Any
advice on where I'm going wrong?


An out take of the code is below:

In the class I have the following variables

static KeyStore keyStore;
String filenameKeyStore = "KeyStore.kstore";


Then the following two functions

        public KeyHandler(Context context) {


                if(keyStore == null) {
                        Log.d("KeyStore", "Keystore is null so loading");
                        if(initialiseKeyStore(context) == false) {
                                // KeyStore failed to initialise
                                Log.e("ERROR", "Store failed to initialise");
                        }
                }
        }


private boolean initialiseKeyStore(Context context) {
                FileInputStream input = null;
                try {
                        // Get an instance of KeyStore
                        keyStore = KeyStore.getInstance("BKS");

                        // Load the KeyStore file
                        try {

                                // Try and open the private key store
                                input = context.openFileInput(filenameKeyStore);

                        } catch (FileNotFoundException e) {

                                // If  the file doesn't exist then create the 
file, a ECDH key and
store the key
                                Log.w("Warning","File does not exist, creating 
new file");

                                try {
                                        // Load the default Key Store
                                        keyStore.load(null, null);

                                        // Create the file
                                        FileOutputStream output =
context.openFileOutput(filenameKeyStore, 0);

                                        // Reset private key
                                        resetPrivateKey(context);

                                        // Save the key
                                        keyStore.store(output, 
"password".toCharArray());

                                        // Close the keystore and set the input 
stream
                                        output.close();
                                        input = 
context.openFileInput(filenameKeyStore);

                                        // Reset the keyStore
                                        keyStore = KeyStore.getInstance("BKS");

                                } catch (FileNotFoundException ee) {
                                        Log.e("ERROR", "File not found, even 
though we just created it");
                                        return false;
                                } catch (NoSuchProviderException e1) {
                                        // BC isn't working exit
                                        e1.printStackTrace();
                                        System.exit(1);
                                } catch (InvalidAlgorithmParameterException e1) 
{
                                        Log.e("ERROR", "The algorithm used for 
secure algorithm is
incorrect");
                                        e1.printStackTrace();
                                        return false;
                                }
                        }


                        // Load the store
                        keyStore.load(input, "password".toCharArray());

                } catch (KeyStoreException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        return false;
                } catch (CertificateException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        return false;
                }  catch (EOFException e) {

                      // Where the exception is caught

                        e.printStackTrace();
                        return false;
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        return false;
                } catch (NoSuchAlgorithmException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        return false;
                } catch (NoSuchProviderException e) {
                        // Serious error, return
                        e.printStackTrace();
                        System.exit(1);
                }

                return true;
        }

-- 

2. options menu items



unfortunately, you can't

pskink

-- 

3. moving the softkeyboard from place

4. Android legal issues

5. Banyak yg spt Android

6. Issues on porting android to beagle like board

7. How to run android application from super user(administrator) mode