Timer cause memory leak

by James Wang » Sat, 27 Feb 2010 11:58:36 GMT


Sponsored Links
 I have three activities:MyFirstActivity(click)->MyActivity(timer)-
And I noticed Timer cause MyActivity memory leak when digging through
hprof in Eclipse.
Below is my codes:
public class MyActivity extends Activity {

    private Timer timer = new Timer();

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TimerTask task = new TimerTask() {
            public void run() {
                Intent intent = new Intent();

                intent.setClassName(getPackageName(),
MyNextActivity.class.getName());
                startActivity(intent);
                finish();
            }
        };
        timer.schedule(task, INTERVAL_TIME);
    }

    public void onDestroy() {
        super.onDestroy();
        //memory leaking happens if there is not below.
        //timer = null;
    }
}

If I did set timer to null in onDestroy, MyActivity will always exist
in heap. I did the flow four times and found four timers and four
MyActivity instances in heap.

Who can tell me why?

--



Other Threads

1. About progress dialogs

Hello!

I want to use this to put while is doing a heavy operation. Here's the
code:

ProgressDialog PD = ProgressDialog.show(History.this, "", "Deleting,
please wait");
for (int i=0;i<idCodesLenght;i++){
        db.open();
        db.deleteCode(idCodes[i]);
        db.close();
}
loadList();
lv = getListView();
PD.cancel();

Like you see...what I want to delete all the content in the database.
So depending of the volume of info it has, it can be get more or less
time.

The problem is that....I don't see the progress dialog... :S, even if
it's fast or if it's slow....

What happens to it?

-- 

2. Is it possible to use 2.6.31 linux kernel with android 2.1

Hello!

Is it possible to use linux kernel 2.6.31 with android 2.1?
I have red at http://pdk.android.com/online-pdk/guide/bring_up.html
that linux kernel for android need support only:
#
# Android
#
# CONFIG_ANDROID_GADGET is not set
# CONFIG_ANDROID_RAM_CONSOLE is not set
CONFIG_ANDROID_POWER=y
CONFIG_ANDROID_POWER_STAT=y
CONFIG_ANDROID_LOGGER=y
# CONFIG_ANDROID_TIMED_GPIO is not set
CONFIG_ANDROID_BINDER_IPC=y

However in /core/init/init.c i found that it uses ASHMEM device. But there is 
no support for ASHMEM in 31 kernel.
So what about this?

Also i red in some forums regarding CPU TLS hardware register. Some new 
platforms (for ex. cortex) has it's hardware support, some - doesn't. What 
about Android? Does it use hardware or software TLS?

Also i didn't find armv6 architecture in Android buid system. Only armv5te and 
armv7. Will android support armv6 architecture, or is there any patch available 
to support armv6 architecture in Android?

Thanks!

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. Dipilih dipilih dipilihhhhh.....

4. Problem with Network Access with HttpClient using AsyncTask (or Thread directly)

5. Questions about drawPosText

6. N1 Desire Rom FLASH error

7. Relative Layout problem :(