Thanks so much for replying.

Unfortunately I've altered the code to actually start the TestThread
and it still doesn't hit the breakpoint. Is there any way of
implementing this without leaking TestThreads?

package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        tv.setText("Hello, Android");
        setContentView(tv);

        TestThread t = new TestThread();
        t.start();
        try {
                        t.join();
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }
        t = null;
        System.gc();
    }

    class TestThread extends Thread {
        @Override
        public void run() {
        }

        protected void finalize() throws Throwable {
                super.finalize();
        }
    }
}

On Jun 23, 2:55 pm, fadden <fad...@android.com> wrote:
> On Jun 22, 11:19 pm, Drifter <daveh...@yahoo.co.uk> wrote:
>
> > I don't seem to able to get a Thread to be garbage collected. Below is
> > the source code (modified from HelloAndroid). I put a break point in
> > the finalize function and it never seems to get called. If I remove
> > "extends Thread" from the TestThread definition then the finalize
> > function gets called as expected. What's going on?
>
> What's going on is the implementation of java.lang.Thread is adding
> the object to a ThreadGroup when the object is first created.
> However, the ThreadGroup.remove() call is only made from inside the VM
> when a thread exits.  Since the thread is never started, it's never
> removed from the ThreadGroup, and you're leaking TestThread objects.
>
> This would be a bug.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to