File: 72destruction.t

package info (click to toggle)
libxml-libxml-perl 2.0116%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,420 kB
  • sloc: perl: 6,139; ansic: 3,752; xml: 182; sh: 64; makefile: 8
file content (48 lines) | stat: -rw-r--r-- 915 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use strict;
use warnings;
use Test::More;
use Scalar::Util;
use XML::LibXML;

if (defined (&Scalar::Util::weaken))
{
    plan tests => 1;
}
else
{
    plan skip_all => 'Need Scalar::Util::weaken';
}

my $is_destroyed;
BEGIN
{
    no warnings 'once', 'redefine';
    my $old = \&XML::LibXML::Element::DESTROY;
    *XML::LibXML::Element::DESTROY = sub
    {
        $is_destroyed++;
        $old->(@_);
    };
}

# Create element...
my $root = XML::LibXML->load_xml( IO => \*DATA )->documentElement;

# allow %hash to go out of scope quickly.
{
    my %hash = %$root;
    # assignment to ensure block is not optimized away
    $hash{foo} = 'phooey';
}

# Destroy element...
undef($root);

# Touch the fieldhash...
my %other = %{ XML::LibXML->load_xml( string => '<foo/>' )->documentElement };

# TEST
ok($is_destroyed, "does not leak memory");

__DATA__
<root attr1="foo" xmlns:x="http://localhost/" x:attr2="bar" />