jackfrued / jackfrued/Python-100-Days
Day16-20 中的循环引用例子可以再补充下
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 187k
- Forks
- 55.8k
- PR merge metrics
- No merged PRs in 30d
Description
目前循环引用的例子为
# 循环引用会导致内存泄露 - Python除了引用技术还引入了标记清理和分代回收
# 在Python 3.6以前如果重写__del__魔术方法会导致循环引用处理失效
# 如果不想造成循环引用可以使用弱引用
list1 = []
list2 = []
list1.append(list2)
list2.append(list1)
代码虽然体现了循环引用,但是这并不是会造成内存泄漏问题的。循环引用例子我觉得最直观的是,有几个unreachable的object,例如
https://www.educative.io/courses/a-quick-primer-on-garbage-collection-algorithms/jR8ml 中的

上图中delete A,delete C,就会发现unreachable的BDE内存泄漏。
而且,此处再举个__del__的例子更好。我觉得这段内容也应该让人知道什么是python3.6以前不能解决的。
比如链接的示例代码:http://engineering.hearsaysocial.com/2013/06/16/circular-references-in-python/
为了让读者更清楚自己应该做什么,可以对读者的建议:
在没有自己定制__del__方法时,不用担心循环引用会造成gc问题。如果自己定制了__del__方法,并且python版本较早,则需要注意。
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Day16-20 circular-reference example in the learning materials and review the linked garbage-collection examples. Update the explanation with an unreachable-object case and the historical del behavior, then ensure the reader guidance clearly distinguishes modern Python from older versions and explains when weak references matter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100