linux下.fa文件怎样用python求GC含量

默认分类 未结 1 995
0o莪蕞拽卜o0
0o莪蕞拽卜o0 2023-11-27 09:23
相关标签:
1条回答
  • 2023-11-27 09:52

    在Python中,为了解决内存泄露问题,采用了对象引用计数,并基于引用计数实现自动垃圾回收。由于Python 有了自动垃圾回收功能,就造成了不少初学者误认为不必再受内存泄漏的*扰了。但如果仔细查看一下Python文档对 __del__() 函数的描述,就知道这种好日子里也是有阴云的。下面摘抄一点文档内容如下:Some common situations that may prevent the reference count of an object from going to zero include: circular references between objects (e.g., a doubly-linked list or a tree data structure with parent and child pointers); a reference to the object on the stack frame of a function that caught an exception (the traceback stored in sys.exc_traceback keeps the stack frame alive); or a reference to the object on the stack frame that raised an unhandled exception in interactive mode (the traceback stored in sys.last_traceback keeps the stack frame alive).可见,有 __del__() 函数的对象间的循环引用是导致内存泄漏的主凶。但没有__del__()函数的对象间的循环引用是可以被垃圾回收器回收掉的。如何知道一个对象是否内存泄露掉了呢?可以通过Python的扩展模块gc来查看不能回收掉的对象的详细信息。

    0 讨论(0)
提交回复