<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/830" rel="nofollow">http://projects.scipy.org/numpy/ticket/830</a> on 2008-06-24 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/cournape/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/cournape">@cournape</a>, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/cournape/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/cournape">@cournape</a>.</em></p>
<p dir="auto">See ticket 493 from scipy trac</p>
<p dir="auto">Dividing by zero (e.g. 1/scipy.float64(0.)) yields scipy.inf as it is supposed to, but leaks memory in the process.</p>
<p dir="auto">I'll attach a sample program where memory usage grows without bound.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!python
import scipy
x = scipy.float64(0.)
while 1:
    1/x"><pre class="notranslate"><code class="notranslate">#!python
import scipy
x = scipy.float64(0.)
while 1:
    1/x
</code></pre></div>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/955" rel="nofollow">http://projects.scipy.org/numpy/ticket/955</a> on 2008-11-20 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/stefanv/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/stefanv">@stefanv</a>, assigned to unknown.</em></p>
<p dir="auto">From <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=505999" rel="nofollow">http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=505999</a>:</p>
<p dir="auto">Version: 1:1.1.0-3</p>
<p dir="auto">Raising zero to a negative power sometimes leaks memory, depending on the<br>
types involved. While this is easy to work around (check for zero and deal<br>
with it separately), it shouldn't happen.</p>
<p dir="auto">In particular, with the following combinations of types (where the base is<br>
0 and the exponent is -3 or -3.5), one object is leaked:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<p dir="auto">(In addition, float ** numpy.int32 raises an exception; however, strictly<br>
speaking, that would be a separate issue.)</p>
<p dir="auto">Code to reproduce this is enclosed below.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!/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()&gt;before:
                print 'leak: ', type(z), '**', type(p)
            else:
                print 'OK:   ', type(z), '**', type(p)
        except:
            print 'error:', type(z), '**', type(p)"><pre class="notranslate"><code class="notranslate">#!/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()&gt;before:
                print 'leak: ', type(z), '**', type(p)
            else:
                print 'OK:   ', type(z), '**', type(p)
        except:
            print 'error:', type(z), '**', type(p)
</code></pre></div>