文章詳情頁
python 為什么調(diào)用函數(shù)會令引用計數(shù)+2
瀏覽:119日期: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 ’函數(shù)調(diào)用,計數(shù)器增加’, sys.getrefcount(c) - 1 - init_cnt ####函數(shù)調(diào)用,計數(shù)器增加 2function(a)
問題解答
回答1:把a當參數(shù)傳入到function后被引用了兩次:
for attr in dir(function): print attr, getattr(function, attr)
可以看到參數(shù)a被function這個對象中的兩個屬性分別引用.
相關(guān)文章:
1. bootstrp是col-md-12列的,只有col-md-10有內(nèi)容,可以讓沒有內(nèi)容的不占據(jù)位置嗎;2. android - Genymotion 微信閃退 not find plugin.location_google.GoogleProxyUI3. wordpress里,這樣的目錄列表是屬于小工具還是啥?4. python - Fiddler+Android模擬器抓取app,json數(shù)據(jù)被加密了,如何解析?5. python如何設置一個隨著系統(tǒng)時間變化的動態(tài)變量?6. 我的怎么不顯示啊,話說有沒有QQ群什么的7. mysql federated引擎無法開啟8. MySQL 使用 group by 之后然后 IFNULL(COUNT(*),0) 為什么還是會獲得 null9. 常量在外面不加引號會報錯。10. sublime text3安裝package control失敗
排行榜

熱門標簽