I appear to have a memory leak(s) in my application, and I am trying
to get a handle on it by trying to understand more about garbage
collection. I have created the following application.
Here I have a class 'MyClass', and I create an instance of that class
in my 'onCreate'. I then null out the pointer which should leave no
references to that instance.
In 'MyClass', I override the finalize method so that I can see when
the object is destroyed. When I run this program, the finalize method
is never called, even if I call System.gc(), from within my program,
or use the 'Cause GC' button using DDMS. (This is the same behavior
that I see in my full application, by the way).
Can someone explain to me more about what is going on here. I believe
that in my main application, that I have objects that are not being
freed. Is there some strategy for identifying those objects?
Thanks.
/*
* Main Activity
*/
package com.gabysoft.memoryleak;
import android.app.Activity;
import android.os.Bundle;
public class MemoryLeak extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
MyClass mc = new MyClass();
mc = null;
setContentView(R.layout.main);
System.gc();
}
}
/*
* My Class
*/
package com.gabysoft.memoryleak;
import android.util.Log;
public class MyClass extends Object
{
MyClass()
{
Log.d("GabySoft", "MyClass::MyClass() " + this);
}
@Override
protected void finalize()
{
Log.d("Gabysoft", "MyClass::finalize() " + this);
}
}
--
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