[Numpy-tickets] [NumPy] #955: [debian #505999] memory leak in exponentiation

NumPy numpy-tickets@scipy....
Thu Nov 20 00:20:46 CST 2008


#955: [debian #505999] memory leak in exponentiation
------------------------+---------------------------------------------------
 Reporter:  stefan      |       Owner:  somebody   
     Type:  defect      |      Status:  new        
 Priority:  normal      |   Milestone:  1.1.2      
Component:  numpy.core  |     Version:  none       
 Severity:  normal      |    Keywords:  memory leak
------------------------+---------------------------------------------------
 From http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=505999:

 Version: 1:1.1.0-3

 Raising zero to a negative power sometimes leaks memory, depending on the
 types involved. While this is easy to work around (check for zero and deal
 with it separately), it shouldn't happen.

 In particular, with the following combinations of types (where the base is
 0 and the exponent is -3 or -3.5), one object is leaked:

 {{{
 float ** numpy.float64
 int ** numpy.float64
 int ** numpy.int32
 int ** numpy.int64
 numpy.float32 ** numpy.float32
 numpy.float64 ** float
 numpy.float64 ** int
 numpy.float64 ** numpy.float32
 numpy.float64 ** numpy.float64
 numpy.float64 ** numpy.int32
 numpy.float64 ** numpy.int64
 numpy.int32 ** int
 numpy.int32 ** numpy.int32
 numpy.int64 ** int
 numpy.int64 ** numpy.int32
 numpy.int64 ** numpy.int64
 }}}

 (In addition, float ** numpy.int32 raises an exception; however, strictly
 speaking, that would be a separate issue.)

 Code to reproduce this is enclosed below.

 {{{
 #!/usr/bin/python

 import gc, numpy

 def mem():
     gc.collect()
     return len(gc.get_objects())

 for zt in int, float, numpy.int32, numpy.int64, numpy.float32,
 numpy.float64:
     z = zt(0)
     for pt in int, float, numpy.int32, numpy.int64, numpy.float32,
 numpy.float64:
         if zt in (int, float) and pt in (int, float):
             continue
         p = pt(-3.5)
         try:
             before = mem()
             z**p
             if mem()>before:
                 print 'leak: ', type(z), '**', type(p)
             else:
                 print 'OK:   ', type(z), '**', type(p)
         except:
             print 'error:', type(z), '**', type(p)

 }}}

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


More information about the Numpy-tickets mailing list