简体   繁体   English

是将WWW :: Mechanize :: Firefox与mozrepl破坏对象断开连接的唯一方法吗?

[英]Is the only way to disconnect WWW::Mechanize::Firefox from mozrepl destruction of the objects?

As the title says I'm trying to make a perl daemon which, being long-running I want to be sane on resource usage. 如标题所示,我正在尝试制作一个perl守护程序,该守护程序长期运行,希望对资源使用保持理智。

All the examples / documentation I've seen doesn't seem to mention a way to disconnect a session. 我见过的所有示例/文档似乎都没有提到断开会话的方法。

The best documentation on the topic I can find in WWW::Mechanize::Firefox::Troubleshooting Where it's suggested the object (and connection?) is kept alive until global destruction. 我可以在WWW :: Mechanize :: Firefox :: Troubleshooting上找到有关该主题的最佳文档。建议将对象(和连接?)保存到活动状态,直到全局销毁为止。

In short, I've seen no 'disconnect' function, and wonder if I'm missing something. 简而言之,我没有看到“断开连接”功能,想知道我是否丢失了某些东西。

Disconnection seems to be handled via destructors. 断开连接似乎是通过析构函数处理的。 Perl uses special DESTROY methods for this. Perl为此使用了特殊的DESTROY方法。 It is not advisable to call this method manually. 建议不要手动调用此方法。

You need to decrease the refcount of your $mech object in order to get it destroyed automatically. 您需要减少$mech对象的引用计数,以使其自动销毁。 This happens when the variable drops out of scope, in the Global Destruction Phase at the end of the process, or (in the case of objects), by assigning something different to your variable, eg 当变量超出范围时,在过程结束时在全局销毁阶段或(通过对象)为变量分配不同的东西时,就会发生这种情况

$mech = undef;

To completely deallocate any variable, you can also 要完全取消分配任何变量,您还可以

undef $mech; # which btw is the answer provided in the FAQ you linked

The differences are subtle, and irrelevant in this case. 在这种情况下,差异是微妙的且无关紧要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM