[SciPy-User] Memory Leak? Problems with deleting numpy arrays.

Sebastian Walter sebastian.walter@gmail....
Fri Nov 5 11:38:51 CDT 2010


On Thu, Nov 4, 2010 at 2:44 AM, David Baddeley
<david_baddeley@yahoo.com.au> wrote:
> If you want python to garbage collect it, the reference count should only be 1
> when you return it to python - are you 'incref'ing it somewhere in your c code?
> It will get garbage collected when the ref count drops to zero, and deleting it
> just drops it by one.

Is it like that on the C side?
In Python it is always one larger than it should be:

In [17]: import sys

In [18]: import numpy

In [19]: x = numpy.array([1,2,3])

In [20]: sys.getrefcount(x)
Out[20]: 2

Sebastian






>
> David
>
>
> ----- Original Message ----
> From: Stuart Wilkins <swilkins@bnl.gov>
> To: scipy-user@scipy.org
> Sent: Thu, 4 November, 2010 1:30:09 PM
> Subject: [SciPy-User] Memory Leak? Problems with deleting numpy arrays.
>
> Hi,
>
> I am having some difficulty with memory management with numpy arrays. I have
> some c-code which creates a numpy array which is fairly large (2 Gb), this is
> passed back to python. Checking the reference count, it is 2 at this point.
> After performing a further operation, the reference count is still 2 and then I
> delete it.
>
>
> The problem is that the memory never gets released. It does not take too many
> passes for this  to basically fail as the system runs out of memory.
>
> So? Does anyone have any ideas? I can send code later. What should the ref count
> be before del to ensure that the object is garbage collected?
>
>
> I find calling gc.collect() does not solve the problem.
>
> Any ideas?
> S
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list