文章详情页
python 为什么调用函数会令引用计数+2
浏览:149日期:2022-08-05 10:36:08
问题描述
import sysa = 11init_cnt = sys.getrefcount(a) - 1print 'init', init_cnt####init 22def function(c): print ’in function, count: ’, sys.getrefcount(c) - 1 ####in function, count: 24 print ’函数调用,计数器增加’, sys.getrefcount(c) - 1 - init_cnt ####函数调用,计数器增加 2function(a)
问题解答
回答1:把a当参数传入到function后被引用了两次:
for attr in dir(function): print attr, getattr(function, attr)
可以看到参数a被function这个对象中的两个属性分别引用.
相关文章:
1. angular.js - ng-grid 和tabset一起用时,grid width默认特别小2. python for循环中的函数只能运行一次?3. android - 美团筛选处筛选条件停靠+条件点击滑动到顶部。4. javascript - Vue.js2.0不能使用debounce后大伙一般是如何解决延迟请求的问题的呢。5. python的文件读写问题?6. python - pyspider爬取了接近1G的数据,无法导出csv?7. css - transform-origin 旋转参考点8. 请问是对象还是数组9. html5 - 在一个页面中 初始了两个swiper 不知道哪里错了 一直不对10. html - 爬虫时出现“DNS lookup failed”,打开网页却没问题,这是什么情况?
排行榜
