Subject: | The listener handler wont be removed when its reference is discarded |
Hello,
Because the add_listener method of the driver store the Chrome::DevToolsProtocol::EventListener instance in an array (https://metacpan.org/source/CORION/WWW-Mechanize-Chrome-0.32/lib/Chrome/DevToolsProtocol.pm#L225), the dereference action of this instance don't leave it available to the garbage collector, so the listener instance never execute his DESTROY method, remaining for ever in the array, consuming a crecient amount of memory and multiplying this listener actions.
Attached goes a litle concept proof of the effect.
Thank you.
Subject: | leak_test.pl |
use WWW::Mechanize::Chrome;
my $mech = WWW::Mechanize::Chrome->new();
my $res = $mech->get('https://www.google.com');
do {
my @input = $mech->xpath('//input[@name="q"]');
print 'scalar @{ $mech->driver->listener->{\'DOM.setChildNodes\'} }='. scalar @{ $mech->driver->listener->{'DOM.setChildNodes'} } ."\n";
sleep 1;
} while ( scalar @{ $mech->driver->listener->{'DOM.setChildNodes'} } < 10 );