Created
December 12, 2011 07:16
-
-
Save plu/1465594 to your computer and use it in GitHub Desktop.
Causing memory leak in Mojo::DOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<ul> | |
<li> | |
li level 1 | |
<ul> | |
<li> | |
li level 2 | |
</li> | |
</ul> | |
</li> | |
</ul> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Mojo::DOM; | |
use Memory::Usage; | |
open my $fp, "<memleak.html"; | |
my $html = do { local $/; <$fp>; }; | |
close $fp; | |
my $mu = Memory::Usage->new; | |
$mu->record('starting work'); | |
for ( 1 .. 10000 ) { | |
my $dom = Mojo::DOM->new($html); | |
# every 1000 iteration, record the memory footprint | |
if ( $_ % 1000 == 0 ) { | |
$mu->record("after iteration $_"); | |
} | |
} | |
$mu->dump; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment