[Numpy-discussion] subclassing array in c
Christoph Gohle
christoph.gohle at mpq.mpg.de
Fri Mar 9 02:00:01 EST 2012
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi again,
I don't want to look as if I want other people do my work, so I would like to ask if there is a simple way of tracing memory leaks (without recompiling the python interpreter)?
Cheers,
Christoph
Am 09.03.2012 um 01:22 schrieb Christoph Gohle:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi
> Am 08.03.2012 um 20:39 schrieb Pauli Virtanen:
>
>> 08.03.2012 17:37, Christoph Gohle kirjoitti:
>>> thanks for testing. I have now tried on different platforms. I get
>>> all kinds of crashes on os x (now with numpy 1.6.1) and windows
>>> with numpy 1.6.0. On Ubuntu with numpy 1.3.0 I get a hughe memory
>>> leak...
>>>
>>> Any hints would be welcome.
>>
>> The type object inherits `tp_alloc` from Numpy. This routine always
>> allocates memory of size NPY_SIZEOF_PYARRAYOBJECT for the
>> PyArrayObject. Therefore, the write to new->unit in your
>> __array_finalize__ goes to unallocated memory.
>>
>> This is probably a bug in Numpy --- arrayobject.c:array_alloc should
>> respect the size specified by the subtype.
>>
>> A workaround is probably to specify a suitable tp_alloc routine yourself:
>>
>> PyType_GenericAlloc, /* tp_alloc */
>> unitArray_new, /* tp_new */
>> _PyObject_Del /* tp_free */
>>
> OK, I did that. And I get no more segfaults as far as I can tell. But there is still a memory leak:
>
> In [1]: import spampub
>
> In [2]: a=[spampub.UnitArray(i,{'s':i}) for i in xrange(100000)]
>
> In [3]: del a
>
> after the last two statements, python uses ~60MB more memory than before.
>
> Thanks for your help
> Christoph
>> --
>> Pauli Virtanen
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> Christoph Gohle
> - --
> Max-Planck-Institut für Quantenoptik
> Abteilung Quantenvielteilchensysteme
> Hans-Kopfermann-Strasse 1
> 85748 Garching
>
> christoph.gohle at mpq.mpg.de
> tel: +49 89 32905 283
> fax: +49 89 32905 313
>
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
>
> iEYEARECAAYFAk9ZTVgACgkQLYu25rCEIztbcwCfcyeQ+FtKTOwFUGbleX/CrjPi
> nZcAnj86kejcAO45YbX+I+rxhU9kq4PU
> =KGdt
> -----END PGP SIGNATURE-----
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
Christoph Gohle
- --
Max-Planck-Institut für Quantenoptik
Abteilung Quantenvielteilchensysteme
Hans-Kopfermann-Strasse 1
85748 Garching
christoph.gohle at mpq.mpg.de
tel: +49 89 32905 283
fax: +49 89 32905 313
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
iEYEARECAAYFAk9ZqnQACgkQLYu25rCEIzthWACgi0dYy2nh83w57Ho8emkvJZ8z
KrkAnistJfaU29tzul8nrJBYsrdmksJk
=Iyr4
-----END PGP SIGNATURE-----
More information about the NumPy-Discussion
mailing list