首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Python之美[从初学者到高手]-Python垃圾回收机制及gc模块详解

2013-10-08 
Python之美[从菜鸟到高手]--Python垃圾回收机制及gc模块详解Python中的垃圾回收是以引用计数为主,标记-清

Python之美[从菜鸟到高手]--Python垃圾回收机制及gc模块详解

    Python中的垃圾回收是以引用计数为主,标记-清除和分代收集为辅。引用计数最大缺陷就是循环引用的问题,所以Python采用了辅助方法。本篇文章并不详细探讨Python的垃圾回收机制的内部实现,而是以gc模块为切入点学习Python的垃圾回收机制,如果想深入可以读读<<Python源码剖析>>。

   看如下代码:


哦,该函数Docstring中说返回值通常比我们期望的要多1,因为传给该函数的参数临时变量又增加了一次引用。原来是这样,但让人很奇怪的是,为啥不调整一下呢???

gc.collect()返回此次垃圾回收的unreachable(不可达)对象个数。那什么是unreachable对象呢?请看下面一段代码:


  分代收集的思想就是活的越久的对象,就越不是垃圾,回收的频率就应该越低。所以当Python发现进过几次垃圾回收该对象都是reachable,就将该对象移到二代中,以此类推。那么Python中又是如何检查各个代是否达到阀值的呢?Python中每次会从三代开始检查,如果三代中的对象大于阀值将同时回收3,2,1代的对象。如果二代的满足,将回收2,1代中的对象,设计的是如此的美。


    

3楼suannai031421分钟前
您的文章已被推荐到博客首页和个人页侧边栏推荐文章,感谢您的分享。
Re: yueguanghaidao21分钟前
呵呵 ,谢谢
2楼u0120551641小时前
http://hefei.baixinger.com/InfoDetail_459_2349708.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349728.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349744.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349764.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349780.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349790.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349796.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349802.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349812.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349825.html
1楼u0120551645小时前
http://hefei.baixinger.com/InfoDetail_459_2349708.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349728.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349744.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349764.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349780.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349790.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349796.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349802.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349812.htmlnhttp://hefei.baixinger.com/InfoDetail_459_2349825.html

热点排行