Python垃圾收集器文档 [英] Python garbage collector documentation

查看:84
本文介绍了Python垃圾收集器文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找详细描述python垃圾收集如何工作的文档。



我对哪一步完成了什么感兴趣。这3个集合中有哪些对象?每一步中删除了哪些对象?什么算法用于引用循环查找?



背景:我正在实施一些搜索,这些搜索必须在少量时间内完成。当垃圾收集器开始收集最老的一代时,它比其他情况下慢得多。它花费的时间比预期用于搜索的时间多。我正在研究如何预测何时它将收集最老的一代,以及需要多长时间。



很容易预测何时它将收集最旧的一代,其中 get_count() get_threshold()。这也可以用 set_threshold()来操纵。但我不明白如何通过强制或等待计划收集来更好地制作 collect()

解决方案



关于Python如何处理它的垃圾没有明确的资源(除了源代码本身),但这3个链接应该给你一个很好的主意。



更新



来源实际上很有帮助。你从中得到多少取决于你阅读C的程度,但评论其实非常有帮助。跳至
collect() function https:// github.com/python/cpython/blob/master/Modules/gcmodule.c ,这些评论很好地解释了这个过程(尽管技术含量很高)。


I'm looking for documents that describes in details how python garbage collection works.

I'm interested what is done in which step. What objects are in these 3 collections? What kinds of objects are deleted in each step? What algorithm is used for reference cycles finding?

Background: I'm implementing some searches that have to finish in small amount of time. When the garbage collector starts collecting the oldest generation, it is "much" slower than in other cases. It took more time than it is intended for searches. I'm looking how to predict when it will collect oldest generation and how long it will take.

It is easy to predict when it will collect oldest generation with get_count() and get_threshold(). That also can be manipulated with set_threshold(). But I don't see how easy to decide is it better to make collect() by force or wait for scheduled collection.

解决方案

There's no definitive resource on how Python does its garbage collection (other than the source code itself), but those 3 links should give you a pretty good idea.

Update

The source is actually pretty helpful. How much you get out of it depends on how well you read C, but the comments are actually very helpful. Skip down to the collect() function at https://github.com/python/cpython/blob/master/Modules/gcmodule.c and the comments explain the process well (albeit in very technical terms).

这篇关于Python垃圾收集器文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆