J
Jacob
I have objects that are added as listeners
to various system events (such as change of
language or units etc.).
To subscribe to such events I typically call
someManager.addListener(this); and the "this"
object will be added in a subscription list
of someManager.
My problem is when these objects are no longer
needed. Normally they would be GC'd, but because
of the subscription references they are not,
and the memory is in effect lost.
My current approach is to have a destroy()
method on these objects where I unsubscribe
to system events (removeListener). I am then
forced to think C++ and figure out when the
object actually dies and call the destroy()
method there, which is a pain as it may
include calling destroy() of children objects
etc. and in general it will be very hard to
get rid of them all.
As I assume my architechture is commonplace,
some of you might have a brigther solution
to the problem?
Thanks!
to various system events (such as change of
language or units etc.).
To subscribe to such events I typically call
someManager.addListener(this); and the "this"
object will be added in a subscription list
of someManager.
My problem is when these objects are no longer
needed. Normally they would be GC'd, but because
of the subscription references they are not,
and the memory is in effect lost.
My current approach is to have a destroy()
method on these objects where I unsubscribe
to system events (removeListener). I am then
forced to think C++ and figure out when the
object actually dies and call the destroy()
method there, which is a pain as it may
include calling destroy() of children objects
etc. and in general it will be very hard to
get rid of them all.
As I assume my architechture is commonplace,
some of you might have a brigther solution
to the problem?
Thanks!