NAME
Test::LeakTrace - Traces memory leaks (EXPERIMENTAL)
VERSION
This document describes Test::LeakTrace version 0.03.
SYNOPSIS
use Test::LeakTrace;
# simple report
leaktrace{
# ...
};
# verbose output
leaktrace{
# ...
} -verbose;
# with callback
leaktrace{
# ...
} sub {
my($ref, $file, $line) = @_;
warn "leaked $ref from $file line\n";
};
my @refs = leaked_refs{
# ...
};
my @info = leaked_info{
# ...
};
my $count = leaked_count{
# ...
};
# standard test interface
use Test::LeakTrace;
not_leaked{
# ...
} "description";
leaked_cmp_ok{
# ...
} '<', 10;
DESCRIPTION
Test::LeakTrace
provides several functions that trace memory leaks.
(TODO)
INTERFACE
Exported functions
- leaktrace { BLOCK }
- leaktrace { BLOCK } -verbose
- leaktrace { BLOCK } \&callback
- leaked_refs { BLOCK }
- leaked_info { BLOCK }
- leaked_count { BLOCK }
- not_leaked { BLOCK } ?$description
-
Tests that BLOCK does not leaks SVs. This is a test function using
Test::Builder
.Note that BLOCK is called more than once. This is because BLOCK might prepare caches which are not memory leaks.
- leaked_cmp_ok { BLOCK } $op, ?$description
-
Tests that BLOCK leakes a specific number of SVs. This is a test function using
Test::Builder
.Note that BLOCK is called more than once. This is because BLOCK might prepare caches which are not memory leaks.
Script interface
Like Devel::LeakTrace
Test::LeakTrace::Script
is provided for whole scripts.
For command line:
$ LEAKTRACE_VERBOSE=1 perl -MTest::LeakTrace::Script script.pl
$ perl -MTest::LeakTrace::Script=1 script.pl
use Test::LeakTrace::Script
also accepts a callback function as follows.
#!perl
# ...
use Test::LeakTrace::Script sub{
my($ref, $file, $line) = @_;
# ...
};
# ...
EXAMPLES
Tracing circular references
#!perl-w
use strict;
use Test::LeakTrace;
leaktrace{
my %a;
my %b;
$a{b} = \%b;
$b{a} = \%a;
};
__END__
Testing modules
Here is a test script template that checks memory leaks.
#!perl -w
use strict;
use constant HAS_LEAKTRACE => eval{ require Test::LeakTrace };
use Test::More HAS_LEAKTRACE ? (tests => 1) : (skip_all => 'require Test::LeakTrace');
use Test::LeakTrace;
use Some::Module;
leaked_cmp_ok{
my $o = Some::Module->new();
$o->something();
$o->something_else();
} '<', 1;
DEPENDENCIES
Perl 5.8.1 or later, and a C compiler.
BUGS
No bugs have been reported.
Please report any bugs or feature requests to the author.
SEE ALSO
AUTHOR
Goro Fuji <gfuji(at)cpan.org>.
LICENSE AND COPYRIGHT
Copyright (c) 2009, Goro Fuji. Some rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.