gpt4 book ai didi

perl - 查找 'lost' 变量(循环引用)

转载 作者:行者123 更新时间:2023-12-04 08:06:13 25 4
gpt4 key购买 nike

所以,这有点简单——但如果我像这样设置循环引用:

#!/usr/bin/perl
use strict;
use warnings;

{
my $thing;
my $otherthing;
$thing -> {otherthing} = \$otherthing;
$otherthing -> {thing} = \$thing;
}

我创建了内存泄漏——因为通过引用计数,这里分配的内存永远不会被释放,尽管没有任何外部“访问点”。

所以我想知道 - 在这种情况下,我有什么方法可以 - 通过调试或类似的方式 - “重新发现”这些变量并再次访问它们?

假设我正在考虑一个不那么琐碎的情况 - 你有一个内存泄漏的对象,但想再次“捕捉”它以查看其中的内容,以提示所述对象中的内容以及问题所在开始了。

最佳答案

这只是对问题评论中推荐的模块的一个整理。它包括每个模块的 POD 文档的链接,并引用 姓名 描述 部分。它意味着可以访问。除了名称和描述部分,我没有在任何地方添加或更改作者所写的内容,或从任何地方提取信息
欢迎任何人使用其他模块对其进行更新,只要他们保持这种格式。或者,任何人都可以提请我注意它需要更新的事实,我会在有能力的时候这样做
许多优秀的程序员的英语不太好,所以虽然我试图准确地引用文档,但为了符合这篇文章的目的,我已经删掉了我认为不太相关的部分

Devel::Cycle - Find memory cycles in objects

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.



Devel::LeakTrace::Fast - Indicate where leaked variables are coming from.

Devel::LeakTrace::Fast is a rewrite of Devel::LeakTrace. Like Devel::LeakTrace it uses the pluggable runops feature found in perl 5.6 and later in order to trace SV allocations of a running program.

At END time Devel::LeakTrace::Fast identifies any remaining variables, and reports on the lines in which the came into existence.



Devel::Gladiator - Walk Perl's arena

Devel::Gladiator iterates Perl's internal memory structures and can be used to enumerate all the currently live SVs.

This can be used to hunt leaks and to profile memory usage.



Devel::MAT::Dumper - Write a heap dump file for later analysis

This module provides the memory-dumping function that creates a heap dump file which can later be read by Devel::MAT::Dumpfile. It provides a single function which is not exported, which writes a file to the given path.

The dump file will contain a representation of every SV in Perl's arena, providing information about pointers between them, as well as other information about the state of the process at the time it was created. It contains a snapshot of the process at that moment in time, which can later be loaded and analysed by various tools using Devel::MAT::Dumpfile.



Devel::Peek - A data debugging tool for the XS programmer

Devel::Peek contains functions which allows raw Perl datatypes to be manipulated from a Perl script. This is used by those who do XS programming to check that the data they are sending from C to Perl looks as they think it should look.

关于perl - 查找 'lost' 变量(循环引用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32024688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com