文章详情页
python 为什么调用函数会令引用计数+2
浏览:40日期: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. 网页爬虫 - Python爬虫返回状态码与实际情况不符?2. javascript - IOS没有上APP Store如何实现热更新?3. paramiko - Python tempfile生成的文件能不能拷贝到远程服务器?4. html标签属性元素讲解5. URL访问有问题啊6. mysql - oracle物化视图和临时表的区别是什么?7. MYSQL代码执行错误:FUNCTION any_value does not exist8. node.js - nodejs开发中常用的连接mysql的库9. 微信小程序如何加载h5页面10. python - 能通过CAN控制一部普通的家用轿车吗?
排行榜