Test::LeakTrace(3)
๐ Test::LeakTrace(3) ๐
okay bestie, this is the User Contributed Perl Documentation page for Test::LeakTrace, and it is literally all about tracing memory leaks. no cap, that is the whole vibe. ๐ซถ
๐ธ NAME ๐ธ
Test::LeakTrace - Traces memory leaks โจ
๐ VERSION ๐
This document describes Test::LeakTrace version 0.17. ๐
๐ฆ SYNOPSIS ๐ฆ
Like, here is the whole group chat of how you use it:
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;
no_leaks_ok{
# ...
} 'no memory leaks';
leaks_cmp_ok{
# ...
} '<', 10;
๐ DESCRIPTION ๐
Test::LeakTrace gives you several functions that trace memory leaks. It scans arenas โ the memory allocation system โ so it can detect any leaked SVs in the blocks you give it. ๐
Leaked SVs are SVs which are not released after the end of the scope they have been created. These SVs include global variables and internal caches. For example, if you call a method in a tracing block, perl might prepare a cache for the method. So, to trace true leaks, no_leaks_ok() and leaks_cmp_ok() executes a block more than once. fr fr, that part matters. ๐ญ
๐ฅ INTERFACE ๐ฅ
๐ Exported functions
leaked_info { BLOCK }โ executesBLOCKand returns a list of leaked SVs and places where the SVs come from, i.e.[$ref, $file, $line]. ๐ต๏ธleaked_refs { BLOCK }โ executesBLOCKand returns a list of leaked SVs. โจleaked_count { BLOCK }โ executesBLOCKand returns the number of leaked SVs. ๐ขleaktrace { BLOCK } ?($mode | \&callback)โ executesBLOCKand reports leaked SVs to*STDERR. ๐ข
Defined $modes are:
-simpleโ default. Reports the leaked SV identity (type and address), file name and line number. ๐ธ-sv_dumpโ in addition to-simple, dumps the sv content usingsv_dump(), which also implementsDevel::Peek::Dump(). ๐พ-linesโ in addition to-simple, prints suspicious source lines. ๐-verboseโ both-sv_dumpand-lines. ๐ฃ๏ธ
no_leaks_ok { BLOCK } ?$descriptionโ tests thatBLOCKdoes not leaks SVs. This is a test function usingTest::Builder. โ
Note that BLOCK is called more than once. This is because BLOCK might prepare caches which are not memory leaks. ๐ซถ
leaks_cmp_ok { BLOCK } $cmp_op, $number, ?$descriptionโ tests thatBLOCKleaks a specific number of SVs. This is a test function usingTest::Builder. โ
Note that BLOCK is called more than once. This is because BLOCK might prepare caches which are not memory leaks. ๐ซถ
count_sv()โ counts all the SVs in the arena. ๐งฎ
๐ Script interface
Like Devel::LeakTrace, Test::LeakTrace::Script is provided for whole scripts. ๐ฆ
The arguments of the use Test::LeakTrace::Script directive are the same as leaktrace(). ๐
$ TEST_LEAKTRACE=-sv_dump perl -MTest::LeakTrace::Script script.pl
$ perl -MTest::LeakTrace::Script=-verbose script.pl
#!perl
# ...
use Test::LeakTrace::Script sub{
my($ref, $file, $line) = @_;
# ...
};
# ...
๐ EXAMPLES ๐
๐งช 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;
leaks_cmp_ok{
my $o = Some::Module->new();
$o->something();
$o->something_else();
} '<', 1;
๐ DEPENDENCIES ๐
Perl 5.8.1 or later, and a C compiler. ๐ง
๐ CAVEATS ๐
Test::LeakTrace does not work with Devel::Cover and modules which install their own runops routines, or the perl executor. So if the test functions of this module detect strange runops routines, they do nothing and report okay. ๐
lowkey important: that caveat is not a vibe, it is the actual behavior. ๐
๐ BUGS ๐
No bugs have been reported. ๐
Please report any bugs or feature requests to the author. ๐ฌ
๐ SEE ALSO ๐
Devel::LeakTrace.Devel::LeakTrace::Fast.Test::TraceObject.Test::Weak.
For guts:
perlguts.perlhack.sv.c.
๐ AUTHOR ๐
Goro Fuji(gfx) <gfuji(at)cpan.org>. ๐
๐ LICENSE AND COPYRIGHT ๐
Copyright (c) 2009-2010, Goro Fuji(gfx). All rights reserved. ๐ซถ
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. ๐
signing off: source/version perl v5.42.0, date 2021-01-06, page Test::LeakTrace(3) โ mwah ๐โจ
๐ฆ where this page comes from
- opensuse-leap 16.0: perl-Test-LeakTrace 0.17-160000.2.2 ยท Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Test-LeakTrace 0.17-160000.2.2 ยท Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Test-LeakTrace 0.17-160000.2.2 ยท Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Test-LeakTrace 0.17-160000.2.2 ยท Artistic-1.0 OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms