I am a little confused on whether or not this situation is dangerous:
I have an object which include a reference to a callback listener. At a certain event in the object the callback listener will be called. The implementation of the abstract callback function will then remove the only existing reference to my object. When the callback returns I do other stuff in the event handler and may also manipulate members.
Since the only reference to this object now is gone, will the Dalvik JVM garbage collector attempt to garbage collect my object even though I am doing the remaining stuff in the event handler? And what will the consequences be of this?
I have written some simple and rather useless code to illustrate my situation:
public SomeClass {
public abstract class CallBackListener {
public void abstract callback();
}
private CallBackListener mCb = null;
private OrgObject mObject = null;
public SomeClass() {
mCb = new CallBackListener() {
@Override
public void callback() {
mObject = null;
}
};
mObject = new OrgObject(mCb);
}
}
public class OrgObject {
private SomeClass.CallBackListener mCb = null;
public OrgObject(SomeClass.CallBackListener cb) {
mCb = cp;
}
public void event() {
//call callback
cb.callback();
//do other stuff
}
}
Any inputs on this situation and/or the practice?
Thanks in advance