Ugh -- yep, that was the problem.  Thanks! :-)



On Sep 8, 2:04 pm, Romain Guy <[email protected]> wrote:
> When you do this kind of test, you should force GCs on the system
> process with DDMS, then force GCs in your process and then check how
> many activities you have running.
>
>
>
>
>
> On Tue, Sep 8, 2009 at 10:57 AM, Flying Coder<[email protected]> wrote:
>
> > There appears to be a leak when using PhoneStateListeners.  The
> > following code simply reigsters in onResume and unregisters in onPause
> > a PhoneStateListener.  Repeatedly launch then press BACK (so the app
> > is finished & onDestory is called before the next launch) and the
> > number of activities reported by meminfo will equal the number of
> > launches.  For instance, here is the output I get after launching (and
> > finishing) 11 times in sequence:
>
> > dumpsys meminfo com.example.leak
> > Currently running services:
> >  meminfo
> > ---------------------------------------------------------------------------­----
> > DUMP OF SERVICE meminfo:
> > Applications Memory Usage (kB):
> > Uptime: 12204322 Realtime: 12204322
>
> > ** MEMINFO in pid 1358 [com.example.leak] **
> >                    native   dalvik    other    total
> >            size:     2648     3079      N/A     5727
> >       allocated:     2604     2254      N/A     4858
> >            free:       43      825      N/A      868
> >           (Pss):      913     1305     1475     3693
> >  (shared dirty):     1080     3864      568     5512
> >    (priv dirty):      808      936     1056     2800
>
> >  Objects
> >           Views:       77        ViewRoots:        1
> >     AppContexts:       12       Activities:       11
> >          Assets:        2    AssetManagers:        2
> >   Local Binders:       36    Proxy Binders:       21
> > Death Recipients:        0
> >  OpenSSL Sockets:        0
>
> >  SQL
> >            heap:        0          dbFiles:        0
> >       numPagers:        0   inactivePageKB:        0
> >    activePageKB:        0
> > #
>
> > Without the PhoneStateListener, the number of activities is always 1
> > no matter how many times the app is launched & finished.  So, am I
> > doing anything wrong here?  Or is this a bug in the
> > TelephonyManager?
>
> > Thanks,
> > Steve
>
> > ############ here's the code
> > package com.example.leak;
>
> > import android.app.Activity;
> > import android.content.Context;
> > import android.os.Bundle;
> > import android.telephony.PhoneStateListener;
> > import android.telephony.TelephonyManager;
> > import android.util.Log;
>
> > public class LeakExample extends Activity {
>
> >        private class MyPhoneStateListener extends PhoneStateListener {
> >               �...@override
> >                public void onCallStateChanged(int state, String 
> > incomingNumber) {
>
> >                        if ((state == TelephonyManager.CALL_STATE_RINGING)
> >                                        || (state == 
> > TelephonyManager.CALL_STATE_OFFHOOK)) {
> >                                LeakExample.this.finish();
> >                        }
> >                }
> >        }
>
> >        MyPhoneStateListener phone_listener = new MyPhoneStateListener();
>
> >        TelephonyManager telMgr ;
>
> >   �...@override
> >    public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.main);
>
> >        telMgr = (TelephonyManager) getSystemService
> > (Context.TELEPHONY_SERVICE);
> >    }
>
> >       �...@override
> >        protected void onPause() {
> >                super.onPause();
>
> >                telMgr.listen(phone_listener, 
> > PhoneStateListener.LISTEN_NONE);
> >        }
>
> >       �...@override
> >        protected void onResume() {
> >                super.onResume();
>
> >                telMgr.listen(phone_listener, 
> > PhoneStateListener.LISTEN_CALL_STATE);
> >        }
>
> >       �...@override
> >        protected void onDestroy() {
> >                super.onDestroy();
>
> >                Log.v("LEAK EXAMPLE", "onDestory");
> >        }
>
> > }
>
> --
> Romain Guy
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time
> to provide private support.  All such questions should be posted on
> public forums, where I and others can see and answer them- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to