[pod] [xml]

名前

Devel::Cycle - オブジェクトのメモリ循環を発見する

概要

  #!/usr/bin/perl
  use Devel::Cycle;
  my $test = {fred   => [qw(a b c d e)],
	    ethel  => [qw(1 2 3 4 5)],
	    george => {martha => 23,
		       agnes  => 19}
	   };
  $test->{george}{phyllis} = $test;
  $test->{fred}[3]      = $test->{george};
  $test->{george}{mary} = $test->{fred};
  find_cycle($test);
  exit 0;
  # output:

Cycle (1): $A->{'george'} => \%B $B->{'phyllis'} => \%A

Cycle (2): $A->{'george'} => \%B $B->{'mary'} => \@A $A->[3] => \%B

Cycle (3): $A->{'fred'} => \@A $A->[3] => \%B $B->{'phyllis'} => \%A

Cycle (4): $A->{'fred'} => \@A $A->[3] => \%B $B->{'mary'} => \@A

説明

This is a simple developer's tool for finding circular references in objects and other types of references. Because of Perl's reference-count based memory management, circular references will cause memory leaks.

このモジュールは、オブジェクトと他のリファレンス型との中にある 循環参照を発見するためのシンプルな開発者用ツールである。 Perlのメモリ管理は参照カウントに基づくため、循環参照は メモリリークを引き起こす。

エクスポート

The find_cycle() subroutine is exported by default.

find_cycle()サブルーチンがデフォルトでエクスポートされる。

The default callback prints out a trace of each cycle it finds. You can control the format of the trace by setting the package variable $Devel::Cycle::FORMATTING to one of "raw," "cooked," or "roasted."

デフォルトのコールバックは、モジュールが発見した各循環のトレースを 出力する。このトレースの形式はパッケージ変数$Devel::Cycle::FORMATTING に"raw"、"cooked"、あるいは"roasted"を設定することで制御できる。

The "raw" format prints out anonymous memory references using standard Perl memory location nomenclature. For example, a "Foo::Bar" object that points to an ordinary hash will appear in the trace like this:

"raw"形式は、Perlの標準的なメモリロケーションの命名法を用いて無名 メモリ参照を出力する。例えば、通常のハッシュをを指す"Foo::Bar" オブジェクトは、トレースの中で次のように現れるだろう:

	Foo::Bar=HASH(0x8124394)->{'phyllis'} => HASH(0x81b4a90)

The "cooked" format (the default), uses short names for anonymous memory locations, beginning with "A" and moving upward with the magic ++ operator. This leads to a much more readable display:

"cooked"形式(デフォルト)は、無名メモリロケーションの短縮名を 使う。これは"A"から始まり、++演算子のマジックによって進んでいく。 これを使えば、より読みやすい表示となる:

        $Foo::Bar=B->{'phyllis'} => \%A

The "roasted" format is similar to the "cooked" format, except that object references are formatted slightly differently:

"roasted"形式は"cooked"形式に似ているが、オブジェクトリファレンスが 若干異なって整形される点が違う。

	$Foo::Bar::B->{'phyllis'} => \%A

For your convenience, $Devel::Cycle::FORMATTING can be imported:

便宜を図って、$Devel::Cycle::FORMATTINGはインポート可能である:

       use Devel::Cycle qw(:DEFAULT $FORMATTING);
       $FORMATTING = 'raw';

参考

Devel::Leak

Scalar::Util

作者

Lincoln Stein, <lstein@cshl.edu>

著作権とライセンス

Copyright (C) 2003 by Lincoln Stein

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.