python删除对象引用_使用Python删除内存中的对象
我正在嘗試使用這種方法刪除python中的對(duì)象。我閱讀了Python的文檔,聲明垃圾收集器將自動(dòng)刪除未引用的對(duì)象。def check():
class newOb():
def __init__(self,value):
self.value = value
print self.value
return None
class ob:
ins = {}
def cr(self,someuniqueid,value) :
newV = newOb(value)
ob.ins[someuniqueid] = newV ## saving this object refernce to the ob class ins dictionary
return newV
#### Accessing Object ###
someuniqueid = 12
c = ob()
d = c.cr(someuniqueid,123)
print d.value ## will print 123
# now deleting the associated object
del c.ins[someuniqueid]
check()
在最后一步,我將從內(nèi)存中刪除對(duì)象引用
正在使用上述過(guò)程將從內(nèi)存中刪除對(duì)象
如果不是,那么代碼有什么問(wèn)題以及如何糾正它
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的python删除对象引用_使用Python删除内存中的对象的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: ipv6的127位掩码如何表示_子网掩码
- 下一篇: Python习题week1