[Numpy-tickets] [NumPy] #1003: Memory leak: objects not deallocated after using them in an array

NumPy numpy-tickets@scipy....
Sun Feb 8 15:35:33 CST 2009


#1003: Memory leak: objects not deallocated after using them in an array
--------------------+-------------------------------------------------------
 Reporter:  stefan  |       Owner:  somebody
     Type:  defect  |      Status:  new     
 Priority:  normal  |   Milestone:  1.3.0   
Component:  Other   |     Version:  none    
 Severity:  normal  |    Keywords:          
--------------------+-------------------------------------------------------
 Melt van Schoor reported a memory leak, illustrated by the following code:

 {{{
 from numpy import *

 class Lattice:
    def __init__(self, size):
       self.size = size

       self.lat = empty((self.size, self.size), dtype=object)
       for x in range(self.size):
          for y in range(self.size):
             self.lat[x,y]=Location(self)

 # compare with this..
 #      self.lat=[[Location(self) for y in xrange(self.size)] for x in
 xrange(self.size)]

 class Location(list):
     pass
     def __init__(self, parent):
       self.parent=parent  # This line is crucial to triggering the leak

 # To trigger, run this (it will consume increasing amounts of memory)
 for t in xrange(2000000): Lattice(80)
 }}}

-- 
Ticket URL: <http://scipy.org/scipy/numpy/ticket/1003>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list