[Ns-developers] Idiotic question about the callbacks
klaussfreire at gmail.com
Mon Feb 27 11:07:15 PST 2012
On Mon, Feb 27, 2012 at 4:45 AM, Mathieu Lacage
<mathieu.lacage at gmail.com> wrote:
> The equivalent of nullify is already done in the callback destructor.
> The reason you have a problem is because the destructor is never
> called in the first place and the reason this happens is because your
> callback holds a reference to a Ptr<Foo> that itself holds a reference
> to the callback (directly or not). i.e., a reference cycle that needs
> to be broken explicitely, preferably in the DoDispose method. There
> are no magic solutions to that problem except breaking the cycle
> explicitely or using a GC which we considered for a while a few years
You have a third option, which is to break the reference cycles at
construction time by using weak references in key places.
Weak references require quite a bit of machinery, though, and can
complicate things (they may nullify automatically any time due to
someone else releasing the last strong reference).
More information about the Ns-developers