开发者

How can I access the ref count of a Perl hash?

I'm trying to enable the garbage collector of my script to do a better job. There's a ton of memory that it should be able to reclaim, but something is stopping it.

I've used Devel::Cycle a bit and that's allowed me to get closer but I'm not quite there.

How do I find out the current reference count for a Perl hash (the storage for my objects)?

Is there a way to track who is holding a reference to an object? Perhaps a so开发者_运维知识库rt of Tie that says, whenever someone points are this object, remember who that someone is.


You are looking for Devel::Refcount.


If you are worried about returning unused memory to the OS, you should know that is not possible in general. The memory footprint of your Perl program will be proportional to the largest allocation during the lifetime of your program.

See How can I make my Perl program take less memory? in the Perl FAQ list as well as Mini-Tutorial: Perl's Memory Management (as pointed out by @Evan Carroll in the comments).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜