Re: zombie timers

[email protected] (Zefram) Mon, 19 Apr 2004 21:37:18 +0100
Newsgroups perl.loop
Message-ID <[email protected]>
Andy Mortimer wrote:
>I'm sure I'm missing something fundamental here, but ... when should
>timer watchers be destroyed?

After they've fired, they still exist and can be modified and retriggered.
See the "again" method.  You need to explicitly cancel your watchers.
Try this variant of your test program:

#! perl -w

use Event;

sub DESTROY { warn "gone $_[0]" }
sub ping {
        warn "ping $_[0]";
        $_[0]->{w}->cancel;
        undef $_[0]->{w};  # break reference loop
}

{
  my $obj={};
  bless $obj;
  $obj->{w} = Event->timer(after => 1,
               cb => sub { $obj->ping() });
}
{
  my $obj={};
  bless $obj;
  $obj->{w} = Event->timer(after => 2,
               cb => sub { $obj->ping() });
}

Event::loop();

__END__

-zefram