Thanks for all your help.
I've finally figured out the discrepancy. Using the following code, I
ran it through the debugger (in Eclipse, WinXP, emulator) and then ran
it just through the emulator - I get different results. The debugger
shows "TestThread Running" while the non-debugger version shows
"TestThread FinaIizing". I believe the debugger holds a reference to
the TestThread which prevents it from getting garbage collected.
Of course, as you said this is all technically valid since System.gc()
is not guaranteed to do anything, but it's nice to know it won't have
any memory leaks on the final version.
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. */
TextView mTV;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTV = new TextView(this);
mTV.setText("Hello, Android");
setContentView(mTV);
TestThread t = new TestThread();
t.start();
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
t = null;
System.gc();
}
protected void finalize() throws Throwable {
super.finalize();
}
class TestThread extends Thread {
@Override
public void run() {
mTV.setText("TestThread Running");
}
protected void finalize() throws Throwable {
mTV.setText("TestThread Finalizing");
super.finalize();
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---