Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于垃圾回收 #6

Open
xxleyi opened this issue May 26, 2019 · 6 comments
Open

关于垃圾回收 #6

xxleyi opened this issue May 26, 2019 · 6 comments

Comments

@xxleyi
Copy link

xxleyi commented May 26, 2019

BAT_interviews/Python面试题及答案.md at master · lengyue1024/BAT_interviews

在我看到的一些资料里,专门说了 Python 没有采用「标记清除」算法,而只是引用计数和分代技术结合。

请问这个 Python 使用标记清除的说法在哪里参考的呢?

@lengyue1024
Copy link
Owner

可以参考一下这篇文章https://foofish.net/python-gc.html

@xxleyi
Copy link
Author

xxleyi commented May 27, 2019

我看了上面这篇文章,提到的「标记清除」所涉及到的参考文档中并未提及到 Python,更像是针对垃圾回收各类策略的介绍。

我又查了一下,如果以下参考并无太大问题的话,至少在目前的 CPython 实现中,还未采用「标记清除」算法。
Garbage Collection for Python
Making Python 3 more attractive [LWN.net]

以及,在下面这个对比 Python 和 Ruby 的对比中的说法是「某种程度上类似」,那这意思就是不是喽?

In a way, Python’s GC algorithm resembles the mark and sweep algorithm Ruby uses.

Generational GC in Python and Ruby | via @codeship

@wen-fei
Copy link

wen-fei commented Jul 8, 2019

提了呀,仔细看

@xxleyi
Copy link
Author

xxleyi commented Jul 8, 2019

咦,奇怪,怎么感觉和上一次看到的完全不一样…

不管这些了。

问题是在我的了解里, Python 并未引入标记清除,只是在使用引用计数和分代回收相配合。

@wen-fei
Copy link

wen-fei commented Jul 9, 2019

标准的Cpython确实只提了你说的那两个,我又仔细查了一下,理解是这样的:分代回收需要标记清除配合。

@xxleyi
Copy link
Author

xxleyi commented Jul 9, 2019

分代回收中的标记清除应该不是通常的标记清除垃圾回收算法吧?但我确实也不确定,只是觉得这样有点太迂回。

之后有机会再详细了解下。

多谢耐心回复~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants