Preventing cyclic reference memory leaks in Perl

白昼怎懂夜的黑 提交于 2019-12-05 01:19:08

Scalar::Util and specifically the weaken function.

The lvalue $ref will be turned into a weak reference. This means that it will not hold a reference count on the object it references. Also when the reference count on that object reaches zero, the reference will be set to undef. This function mutates the lvalue passed as its argument and returns no value.

Set one - or both - of your references as "weak" and the daisy chain will unravel automagically when the anchors are destructed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!