[Numpy-discussion] Numeric memory leak when building Numeric.array from numarray.array

Alexandre Fayolle alexandre.fayolle at logilab.fr
Mon Dec 11 07:16:21 CST 2006


On Thu, Dec 07, 2006 at 05:36:22PM +0100, Francesc Altet wrote:
> El dj 07 de 12 del 2006 a les 16:50 +0100, en/na Alexandre Fayolle va
> escriure:
> > Hi,
> > 
> > I'm facing a memory leak on an application that has to use numarray and
> > Numeric (because of external dependencies). 
> > 
> > The problem occurs when building a Numeric array from a numarray array:
> > 
> > import Numeric
> > import numarray
> > import sys
> > atest = numarray.arange(200)
> > temp =  Numeric.array(atest)
> > print sys.getrefcount(atest) # prints 3
> > print sys.getrefcount(temp)  # prints 2
> > 
> > I'm running numarray 1.5.2 and Numeric 24.2
> 
> Yeah, it seems like the array protocol implementation in Numeric is
> leaking. Unfortunately, as Numeric maintenance has been dropped, there
> is small chances that this would be fixed in the future.
> 
> > 
> > I can work around this by using an intermediate string representation:
> > 
> > temp = Numeric.fromstring(atest.tostring(), atest.typecode())
> > temp.shape = atest.shape
> 
> Another (faster) workaround would be:
> 
> temp2 = Numeric.fromstring(atest._data, typecode=atest.typecode())

Nice! 

Thanks Francesc.  

-- 
Alexandre Fayolle                              LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
Informatique scientifique:               http://www.logilab.fr/science
Reprise et maintenance de sites CPS:     http://www.migration-cms.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: Digital signature
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20061211/eef339d2/attachment.bin 


More information about the Numpy-discussion mailing list