On Sat, Jan 22, 2000 at 01:08:40AM -0500, [EMAIL PROTECTED] wrote:
> i have been thinking about event.pm and ref counts of watchers. it seems
> to me that class subs like all_watchers() imply you keep class data with
> refs to all existing watchers. this means if a watcher object goes out
> of scope at the higher/caller level, it won't be ref counted to 0 and be
> stopped and garbage collected. this would mean watchers must be
> explicitly stopped to remove them from the system.

Yes.  Initially the implementation relied upon perl refcnts, but due to
perl's refcnting optimizations these are not reliable enough.  It is
almost impossible to predict when a given SV is *really* going out of
scope.

> this is not a bad thing in and of itself. i have a similar problem with
> my higher level events which sit on event.pm. my example is a circular
> link with the accept object. i need the accept object to have a readable
> method and that object also holds the watcher which has a ref to the
> accept object in the cb attribute. there is the circular link. so if the
> accept object goes out of scope it will not be garbage collected and
> memory is leaked and the socket stays open.
> 
> i gather weak references will solve this but that is in 5.6 which will
> be out real soon now! :-)

Yes.

> so i will have to require explicit shutting down of an accept object to
> stop it and cause garbage collection. the shutdown method will stop the
> watcher and break the circular link.
>
> no big problem, just wanted to clear my thoughts on this. let me know
> what you think about it and if you have a better way.

'shutdown' method?  I think you need to call 'cancel'.  If you have
a subclass, you can override the cancel method to add your own
clean up:

sub cancel {
  my ($w)=@_;
  # ...
  $w->SUPER::cancel;
}

I've often thought that maybe Event should switch to weak references to
avoid circular links.  Or perhaps the cancel method should release all
the SVs owned by the Event.  That might be enough to fix the problem,
but I bet someone (maybe me!) is relying on the fact that cancel does
not presently disturb any of the watchers settings.  I'm not sure
what is the best solution.

-- 
"Never ascribe to malice that which can be explained by stupidity."
                            via, but not speaking for Deutsche Bank

Reply via email to