I used this for one of my tests to make sure that the garbage is collected:
use Test::More;
# These tests try to make sure that objects are destroyed when they
# fall out of scope; this requires avoiding circular strong references
use strict;
use warnings;
#plan 'no_plan';
plan tests => 8;
use Chemistry::File::Dumper;
my $dead_atoms = 0;
my $dead_bonds = 0;
my $dead_mols = 0;
{
my $mol = Chemistry::Mol->read("t/mol.pl");
isa_ok( $mol, 'Chemistry::Mol' );
is( scalar $mol->atoms, 8, 'atoms before');
# make sure cloned molecules are also gc'ed
my $mol2 = $mol->clone;
# atom deletion garbage collection test
$mol->atoms(2)->delete;
is( $dead_atoms, 1, "delete one atom - atoms" );
is( $dead_bonds, 4, "delete one atom - bonds" );
is( $dead_mols, 0, "delete one atom - mols" );
}
is( $dead_atoms, 16, "out of scope - atoms" );
is( $dead_bonds, 14, "out of scope - bonds" );
is( $dead_mols, 2, "out of scope - mols" );
sub Chemistry::Mol::DESTROY { $dead_mols++ }
sub Chemistry::Atom::DESTROY { $dead_atoms++ }
sub Chemistry::Bond::DESTROY { $dead_bonds++ }
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|