File: weakref.pl

package info (click to toggle)
libtest-leaktrace-perl 0.17-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 360 kB
  • sloc: ansic: 3,215; perl: 687; makefile: 8
file content (34 lines) | stat: -rw-r--r-- 411 bytes parent folder | download | duplicates (6)
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
#!perl -w

use strict;
use Test::More tests => 1;
use Test::LeakTrace qw(:test);


{
	package X;
	use Scalar::Util qw(weaken);

	sub new{
		my($class) = @_;

		my $self = bless {}, $class;

		return $self;
	}

	sub set_other{
		my($self, $other) = @_;
		weaken($self->{other} = $other) if $other;
		return $self;
	}
}

no_leaks_ok{
	my $a = X->new;
	my $b = X->new;

	$a->set_other($b);
	$b->set_other($a);

};