GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Test2::Tools::MemoryCycle(3) User Contributed Perl Documentation Test2::Tools::MemoryCycle(3)

Test2::Tools::MemoryCycle - Check for memory leaks and circular memory references

version 0.01

 use Test2::V0;
 use Test2::Tools::MemoryCycle;
 my $foo = { bar => 1 };
 
 memory_cycle_ok $foo;  # pass
 
 $foo->{baz} = sub {
   print $foo->{bar}, "\n";
 };
 memory_cycle_ok $foo;  # fail
 done_testing;

Perl's garbage collection has one big problem: Circular references can't get cleaned up. The above example is the sort of thing that sometimes trips me up, where a code reference inside a data structure refers to another part of the data structure. There already exists a good testing module to find these sort of problems: Test::Memory::Cycle, so why write this one? Well that module uses Test::Builder, and this one instead uses Test2::API. If you want to write Test2::Suite tests without pulling in Test::Builder then this is the cycle testing module for you.

This module also uses the standard Exporter interface, instead of letting you specify a test plan. That behavior was once in vogue I guess, but I do not care for it.

 memory_cycle_ok $reference, $message;
 memory_cycle_ok $reference;

Checks that $reference doesn't have any circular memory references.

This module is based on and quite similar to Test::Memory::Cycle. That module is more mature, and has more features. So far I only need the one test function. Other features may be added in the future.

Graham Ollis <plicease@cpan.org>

This software is copyright (c) 2022 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2022-09-29 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.