如何“自由”一个对象/ var? [英] how to "free" an object/var ?

查看:60
本文介绍了如何“自由”一个对象/ var?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建了大量数据或类,

如何销毁它(当不再需要时)?


将其分配给空单?


谢谢,

Stef Mientki

If I create a large array of data or class,
how do I destroy it (when not needed anymore) ?

Assign it to an empty list ?

thanks,
Stef Mientki

推荐答案

Stef Mientki写道:
Stef Mientki wrote:

如果我创建了大量数据或类,

如何销毁它(当不再需要时)?


将它分配给一个空列表?


谢谢,

Stef Mientki
If I create a large array of data or class,
how do I destroy it (when not needed anymore) ?

Assign it to an empty list ?

thanks,
Stef Mientki



当您离开示波器时它将是gc''d或者你可以调用del()来明确摆脱对象,如果它的存在困扰你的话。 />

James

It will be gc''d when you leave the scope or you can call del() to
explicitly get rid of the object if its existence bothers you.

James


James Stroud写道:
James Stroud wrote:

Stef Mientki写道:
Stef Mientki wrote:

>如果我创建了大量数据或类,
如何销毁它(当不再需要时)?

将它分配给一个空列表?

谢谢,
Stef Mientki
>If I create a large array of data or class,
how do I destroy it (when not needed anymore) ?

Assign it to an empty list ?

thanks,
Stef Mientki



它将是gc '当你离开范围或者你可以调用del()来

如果它的存在困扰你,就明确地摆脱它。


James


It will be gc''d when you leave the scope or you can call del() to
explicitly get rid of the object if its existence bothers you.

James



感谢James,

确实,大型物品,有时会困扰我,

并将其分配给空列表需要评论;-)

欢呼,

Stef

thanks James,
indeed, large objects, are sometimes bothering me,
and assigning it to an empty list requires comment ;-)
cheers,
Stef


Stef Mientki< S。**** **********@mailbox.kun.nlwrites:
Stef Mientki <S.**************@mailbox.kun.nlwrites:

如果我创建了大量数据或类,我该如何销毁它? br />
(不再需要时)?
If I create a large array of data or class, how do I destroy it
(when not needed anymore) ?



Python带有垃圾收集,默认情况下启用。

代码停止需要对象后的一段时间,垃圾

收藏家会清理它。


要检查你的Python是否启用了垃圾收集,你可以使用''gc'
'接口模块:


Python 2.4.4(#2,2007年1月13日,17:50:26)

[...]

Python comes with garbage collection, which is enabled by default.
Some time after your code stops needing the object, the garbage
collector will clean it up.

To check whether your Python has garbage collection enabled, you can
use the ''gc'' interface module:

Python 2.4.4 (#2, Jan 13 2007, 17:50:26)
[...]


>> import gc
gc.isenabled()
>>import gc
gc.isenabled()



True

True


>> help(gc)
>>help(gc)



只有当你想要与垃圾交互*时才需要这个模块/>
收藏家,除非你想调整它或关闭它,否则你不会。


-

\不道德:那些有更好的人的道德|

` \时间。 - Henry L. Mencken |
_o__)|

Ben Finney

This module is only needed if you want to *interact* with the garbage
collector, which you won''t unless you want to tune it or turn it off.

--
\ "Immorality: The morality of those who are having a better |
`\ time." -- Henry L. Mencken |
_o__) |
Ben Finney


这篇关于如何“自由”一个对象/ var?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆