[Python.NET] Memory leak with conversion from numpy array to System.Single[]

James tomo.bbe at gmail.com
Fri Dec 2 10:45:46 CET 2011


I have been using Python for .Net quite successfully to access an I/O
library that allows me to perform some numerical calculations in Numpy.
This library primarily requires the data to be fed back as Single Arrays.
However when I perform many conversions from numpy arrays (or even just
lists) to Single[] I am experiencing a memory leak that eventually causes a

The following distills the problem. By switching between the two different
Array types (Single & Double) the leak is controlled so it would seem there
is some issues with Single. It does not appear to matter whether change the
dtype of the numpy array to float32. I have also tried Array.ConvertAll but
the same problem arrises.

import numpy as np
import clr
from System import Array, Single, Double
N = 100000
M = 1000
for i in range(N):
    # Numpy calculations
    A = np.random.random( M )

    # Convert to single array - creates memory leak
    sgl_arry = Array[Single](A)

    # Convert to double array - does NOT create memory leak
    #dbl_arry = Array[Double](A)

    # call library requiring Single[]
    # ....

 Any help would be appreciated.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20111202/0e5ed848/attachment.html>

More information about the PythonDotNet mailing list