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");
        }



}


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to