python ref counting based garbage collection
不用中文都不讓釋出
class Foo:
def __init__(self):
self.other = None
def ref(self, other):
self.other = other
def __del__(self):
print('Foo instance deletion')
# case 1
f = Foo()
del f # you should see deletion msg here
# case 2
f = Foo()
g = Foo()
f.ref(g)
del g
del f # you should see two deletion msgs here
# case 3
f = Foo()
g = Foo()
f.ref(g)
g.ref(f) # create circle refs
del f
del g
# you wont see any deletion msg above
import gc
gc.collect()
# now you will see it
def foo():
try:
print('in')
yield
finally:
print('out')
# case 1
f = foo()
del f
# case 2
f = foo()
next(f)
del f
相關文章
- [Javascript] garbage collectionJavaScript
- [Memory leak] 3. Garbage collection in Closure
- C語言垃圾回收(Garbage Collection)C語言
- 深入理解Java中的Garbage CollectionJava
- Java的垃圾回收(Garbage Collection)機制Java
- 從ASP.NET Core 3.0 preview 特性,瞭解CLR的Garbage CollectionASP.NETView
- Java常見知識點彙總(⑰)——垃圾回收機制(garbage collection-GC)JavaGC
- python-collectionPython
- ☕[JVM技術指南](3)垃圾回收子系統(Garbage Collection System)之垃圾回收器JVM
- GCD CountingGC
- Lake Counting S
- ☕[JVM技術指南](2)垃圾回收子系統(Garbage Collection System)之常見的垃圾回收演算法JVM演算法
- ☕[JVM技術指南](4)垃圾回收子系統(Garbage Collection System)之G1垃圾收集器SATBJVM
- ☕[JVM技術指南](1)垃圾回收子系統(Garbage Collection System)之回收標記和物件引用的介紹JVM物件
- ref
- 【Lintcode】1736. Throw Garbage
- 計數排序 - Counting Sort排序
- PAT Advanced 1004 Counting Leaves
- Collection
- [SPOJ]DIVCNTK - Counting Divisors[數論]
- Codeforces 954H Path Counting
- CF1919E Counting Prefixes
- Spring中ref local=""與ref bean=""的區別SpringBean
- Collection介面
- 容器(collection)
- Laravel CollectionLaravel
- vue --ref用法Vue
- ref屬性
- ref和reactiveReact
- iOS中的Reference Counting詳解iOS
- Rust 中 *、&、mut、&mut、ref、ref mut 的用法和區別Rust
- examples for oracle ref cursorsOracle
- React ref的用法React
- 使用 ref 引用值
- Refactoring to collection(譯)
- Java集合-CollectionJava
- Physically Based Rendering
- Vue 學習 Ref shallowRef triggerRef customRef (Ref 和 Reactive的對比)VueReact