Skip to content

Instantly share code, notes, and snippets.

@plu
Created December 12, 2011 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plu/1465594 to your computer and use it in GitHub Desktop.
Save plu/1465594 to your computer and use it in GitHub Desktop.
Causing memory leak in Mojo::DOM
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul>
<li>
li level 1
<ul>
<li>
li level 2
</li>
</ul>
</li>
</ul>
</body>
</html>
#!/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