SciSharp / NumSharp

High Performance Computation for N-D Tensors in .NET, similar API to NumPy.
https://github.com/SciSharp
Apache License 2.0
1.38k stars 192 forks source link

Memory leak? #501

Open TakuNishiumi opened 11 months ago

TakuNishiumi commented 11 months ago

Hi, I tried below code and usage rate of my memory increased up to around 10GB.

// 配列を宣言する
double[] array = new double[110];

// 乱数を生成する
Random rnd = new Random();

// 配列に乱数を代入する
// make random double array
for (int i = 0; i < array.Length; i++)
{
    array[i] = rnd.NextDouble();
}

// make new NDarray in loop
for (int i = 0; i < 1000000; i++)
{
    NDArray array2 = np.array(array);
    // NDArray array2 = np.argmin(array); also cause same trouble
}

This is also caused when this is used as function. I modified this and add GC.Collect(). This make the code usage rate of my memory, but the calculation time increased.

// 配列を宣言する
double[] array = new double[110];

// 乱数を生成する
Random rnd = new Random();

// 配列に乱数を代入する
// make random double array
for (int i = 0; i < array.Length; i++)
{
    array[i] = rnd.NextDouble();
}

// make new NDarray in loop
for (int i = 0; i < 1000000; i++)
{
    NDArray array2 = np.array(array);
    if (i % 10000 == 0)
    {
        GC.Collect();
    }
}

What should I do next? Do you have any ideas?