[NumPy-Tickets] [NumPy] #1542: Memory leak casting view of object-type ndarray to bool

NumPy Trac numpy-tickets@scipy....
Mon Jul 12 14:06:52 CDT 2010


#1542: Memory leak casting view of object-type ndarray to bool
--------------------+-------------------------------------------------------
 Reporter:  wesm    |       Owner:  somebody
     Type:  defect  |      Status:  new     
 Priority:  normal  |   Milestone:  2.0.0   
Component:  Other   |     Version:          
 Keywords:          |  
--------------------+-------------------------------------------------------
 Seen in NumPy 1.3.0 and NumPy 1.4.1 on Windows XP.

 {{{
 from datetime import datetime
 import numpy as np
 import sys

 def foo(verbose=True):
    arr = np.array([datetime.today() for _ in xrange(1000)])
    arr = arr.reshape((500, 2))
    sl = arr[:, 0]

    if verbose: print 'Rec ct of index 0: %d' % sys.getrefcount(sl[0])

    for _ in xrange(10):
        foo = sl.astype(bool)

    if verbose: print 'Rec ct of index 0: %d' % sys.getrefcount(sl[0])

 if __name__ == '__main__':
    foo()

    # leaks memory
    for i in xrange(10000):
        if not i % 1000: print i
        foo(verbose=False)
 }}}

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1542>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list