数组的内存泄漏问题 [英] memory leak problem with arrays

查看:64
本文介绍了数组的内存泄漏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是python编程的新手,我希望这就是问题所在。


我已经在python中使用numpy数组创建了一个元胞自动机程序

扩展。在每个循环/迭代之后,用于检查的内存和由转换规则确定的
更改数组永远不会被释放。

我尝试过使用del在每个可能的变量上,但是没有b $ b工作。我已经阅读了所有论坛,以获取有关如何做的有用提示,但是

到目前为止还没有任何工作。我甚至尝试过python memory

验证 (beta)程序,在整个计算机崩溃之前确实指向numpy.dtype和

numpy.ndarray作为增加对象。

如果需要,我可以提供代码。我很绝望,因为这是我的论文的一部分,如果我不能解决这个问题,我会尝试另一种编程

语言。


提前感谢

Sonja

解决方案

sonjaa写道:



我是python编程的新手,我希望这就是问题所在。

我创建了一个python中的细胞自动机程序,具有numpy数组扩展。在每个循环/迭代之后,用于检查和更改由转换规则确定的数组的内存永远不会被释放。
我已经尝试使用del在每个可能的变量上,但是没有工作。




Python跟踪每个对象的引用数量,如果

对象在你使用del时有多个引用。对象

未被释放,只有参考数量减少。


打印您认为应该是的所有对象的参考数量

在每个循环/迭代后释放,如果不等于2则意味着你是b / b
持有对这些对象的额外引用。您可以通过调用sys.getrefcount(obj)来获取对任何对象的

引用数量




Serge Orlov写道:

sonjaa写道:



我是python编程的新手,我希望这是问题。

我已经在python中创建了一个带有numpy数组扩展的元胞自动机程序。在每个循环/迭代之后,用于检查和更改由转换规则确定的数组的内存永远不会被释放。
我已经尝试使用del可能的每个变量,但是没有工作。


如果
对象有更多的对象,Python会跟踪每个对象的引用数量在您使用del时的参考对象
没有被释放,只有参考数量减少。

打印每个周期/迭代后你认为应该释放的所有对象的引用数量,如果不等于2意味着你要对这些对象持有额外的引用。您可以通过调用sys.getrefcount(obj)来获取对任何对象的引用数量。




感谢您的信息。我使用了这几个变量/对象和

发现小的计数器,即k = k + 1,有许多引用

它们,上涨tp 10000+。

有没有办法解冻它们?


问候

Sonja


< blockquote> 2006年6月15日上午8:27,sonjaa写道:

Serge Orlov写道:

sonjaa写道:



我是python编程的新手,我希望这就是问题所在。

我已经在python中用numpy数组创建了一个元胞自动机程序
扩展。在每个循环/迭代之后,用于检查和更改由转换规则确定的数组的内存永远不会被释放。
我已经尝试使用del可能的每一个变量,但是没有工作。


如果
对象在时间上有多个引用,Python会跟踪每个对象的引用数量你使用del对象
没有被释放,只有参考数量减少。

打印每个周期/迭代后你认为应该释放的所有对象的引用数量,如果不等于2意味着你要对这些对象持有额外的引用。您可以通过调用sys.getrefcount(obj)来获取对任何对象的引用数量



感谢您的信息。我使用了这几个变量/对象,并且发现小的计数器,即k = k + 1,有许多引用它们,超过tp 10000+。
有没有办法释放它们? / blockquote>


如果(例如)k指的是整数对象10,那么所有这意味着

你有10000多个对象,其值为10对他们的引用

将分散在你的数据结构中。


警告:我不是一个笨拙的用户。现在继续阅读:


我会想到[通过内置的数组推断] numpy允许你声明一个齐次的整数数组

这将是内部整数,而不是python对象整数,其中

的情况下你不会得到10000多个引用任何k的东西。指的是。


建议的方法:阅读numpy手册,发布你的

代码的相关部分,等待一个numpy guru出现。


HTH,

John


Hi

I''m new to programming in python and I hope that this is the problem.

I''ve created a cellular automata program in python with the numpy array
extensions. After each cycle/iteration the memory used to examine and
change the array as determined by the transition rules is never freed.
I''ve tried using "del" on every variable possible, but that hasn''t
worked. I''ve read all the forums for helpful hints on what to do, but
nothing has worked so far. I''ve even tried the "python memory
verification" (beta) program, which did point to numpy.dtype and
numpy.ndarray as increasing objects, before the whole computer crashed.
I can supply the code if needed. I''m desperate because this is part of
my thesis, and if I can''t get this fixed, I''ll try another programming
language.

thanks in advance
Sonja

解决方案

sonjaa wrote:

Hi

I''m new to programming in python and I hope that this is the problem.

I''ve created a cellular automata program in python with the numpy array
extensions. After each cycle/iteration the memory used to examine and
change the array as determined by the transition rules is never freed.
I''ve tried using "del" on every variable possible, but that hasn''t
worked.



Python keeps track of number of references to every object if the
object has more that one reference by the time you use "del" the object
is not freed, only number of references is decremented.

Print the number of references for all the objects you think should be
freed after each cycle/iteration, if is not equal 2 that means you are
holding extra references to those objects. You can get the number of
references to any object by calling sys.getrefcount(obj)



Serge Orlov wrote:

sonjaa wrote:

Hi

I''m new to programming in python and I hope that this is the problem.

I''ve created a cellular automata program in python with the numpy array
extensions. After each cycle/iteration the memory used to examine and
change the array as determined by the transition rules is never freed.
I''ve tried using "del" on every variable possible, but that hasn''t
worked.



Python keeps track of number of references to every object if the
object has more that one reference by the time you use "del" the object
is not freed, only number of references is decremented.

Print the number of references for all the objects you think should be
freed after each cycle/iteration, if is not equal 2 that means you are
holding extra references to those objects. You can get the number of
references to any object by calling sys.getrefcount(obj)



thanks for the info. I used this several variables/objects and
discovered that little counters i.e. k = k +1 have many references to
them, up tp 10000+.
Is there a way to free them?

regards
Sonja


On 15/06/2006 8:27 AM, sonjaa wrote:

Serge Orlov wrote:

sonjaa wrote:

Hi

I''m new to programming in python and I hope that this is the problem.

I''ve created a cellular automata program in python with the numpy array
extensions. After each cycle/iteration the memory used to examine and
change the array as determined by the transition rules is never freed.
I''ve tried using "del" on every variable possible, but that hasn''t
worked.


Python keeps track of number of references to every object if the
object has more that one reference by the time you use "del" the object
is not freed, only number of references is decremented.

Print the number of references for all the objects you think should be
freed after each cycle/iteration, if is not equal 2 that means you are
holding extra references to those objects. You can get the number of
references to any object by calling sys.getrefcount(obj)



thanks for the info. I used this several variables/objects and
discovered that little counters i.e. k = k +1 have many references to
them, up tp 10000+.
Is there a way to free them?



If (for example) k refers to the integer object 10, all that means is
that you have 10000+ objects whose value is 10. The references to them
will be scattered throughout your data structures somewhere.

Caveat: I''m not a numpy user. Now read on:

I would have thought [by extrapolation from the built-in "array" module]
that numpy would allow you to "declare" a homogeneous array of integers
which would be internal integers, not python object integers, in which
case you would not be getting 10000+ references to whatever "k" refers to.

Suggested approaches: read numpy manual, publish relevant parts of your
code, wait for a numpy guru to appear.

HTH,
John


这篇关于数组的内存泄漏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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