thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

Add cyclic garbage collection support to object arrays (migrated from Trac #1003) #2556

Open thouis opened 11 years ago

thouis commented 11 years ago

Original ticket http://projects.scipy.org/numpy/ticket/1003 Reported 2009-02-08 by atmention:stefanv, assigned to unknown.

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)
thouis commented 11 years ago

Comment in Trac by atmention:pv, 2009-02-09

The problem appears to be that Numpy arrayobject doesn't support cyclic garbage collection:

http://docs.python.org/c-api/gcsupport.html

thouis commented 11 years ago

Comment in Trac by atmention:cournape, 2009-03-09

thouis commented 11 years ago

Comment in Trac by atmention:pv, 2010-09-05

thouis commented 11 years ago

Comment in Trac by atmention:mwiebe, 2011-03-24