I've been digging into Android IPC, recently and there's something puzzling
me.
Suppose I define a Parcelable that, as one of its arguments, takes a
callback listener which is also Parcelable.
Like this:
oneway interface MyService {
void start(in MyRequest req, in MyResponseListener listener);
}
oneway interface MyResponseListener {
void onResponse(in MyResponse response);
}
In my code, I'm going to do something like this:
listener = new MyResponseListener() { /*... */ }
boundService.start(req, listener);
I think this is pretty much how Cursors work. I see one of two possibilites
here:
1) the call to start() doesn't create an additional reference to the
listener object. That means that, to prevent its being gc'ed, my code must
keep a reference to the listener, somewhere, until it ether gets the
callback or doesn't want the it anymore. (btw, what happens if the listener
is gone when the callback happens?)
2) the call to start() creates a new, GC-visible reference to listener. I
can pass an anonymous class without fear that it will be GCed. On the
other hand, it and everything to which it holds references are leaked until
that reference gets nulled. When does that happen?
I've followed this down as far as a Parcel.flatten_binder, but I kind of
lose it after that.
What is the right way to keep from leaking, for instance, implicit pointers
to my Activity, when I use asynchronous callbacks with a bound Service?
Thanks
-blake
G. Blake Meike
Marakana
The second edition of Programming Android is now on-line:
http://shop.oreilly.com/product/0636920023005.do
--
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