enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.3k stars 285 forks source link

Memory leak while rendering many images #517

Open solarjoe opened 7 years ago

solarjoe commented 7 years ago

Hello,

there might be a memory leak when rendering many images in a for loop.

WinPython-64bit-3.4.4.1 Mayavi 4.4.4 VTK 7.0.0

Running the code below I can see the "Commit" memory filling up. Once full it crashes the memory frees. The calculations started at the red marks, were stopped or crashed at the black marks. At the blue marks the "Physical memory" started to fill up.

grafik

I don't know exactly on how to interpret this.

Other things I noticed

Here is a working example:

#import gc

import numpy as np
from mayavi import mlab

#mlab.options.offscreen=True

n = 10000
nt = 5000

for k in range(10000):

    x = np.random.rand(n)
    y = np.random.rand(n)
    z = np.random.rand(n)

    triangles = np.random.randint(n, size=(nt, 3))

    fig = mlab.figure(bgcolor=(1.0, 1.0, 1.0), size=(1600, 900))

    mlab.triangular_mesh(x, y, z, triangles, scalars=np.random.rand(n))

    mlab.clf()
    mlab.close(fig)
    mlab.close(all=True)

    #gc.collect()
csbrown commented 5 years ago

@solarjoe, did you discover a workaround for this?

solarjoe commented 5 years ago

No, sorry. Do you see a similar behaviour?

eleboss commented 5 years ago

@solarjoe Put the figure code outside the loop, and just clear the figure not close the window. Then you will find the magic happen. ` import numpy as np from mayavi import mlab

mlab.options.offscreen=True

n = 10000 nt = 5000 fig = mlab.figure(bgcolor=(1.0, 1.0, 1.0), size=(1600, 900)) for k in range(10000):

x = np.random.rand(n)
y = np.random.rand(n)
z = np.random.rand(n)

triangles = np.random.randint(n, size=(nt, 3))

mlab.triangular_mesh(x, y, z, triangles, scalars=np.random.rand(n))

mlab.clf()

`

solarjoe commented 5 years ago

@eleboss, that seems to work, thanks! Any idea why the garbage collection does not work?

eleboss commented 5 years ago

so far, nop. Best.

---Original--- From: "solarjoe"notifications@github.com Date: Thu, Jun 27, 2019 12:52 PM To: "enthought/mayavi"mayavi@noreply.github.com; Cc: "eleboss"jeremyele@Foxmail.com;"Mention"mention@noreply.github.com; Subject: Re: [enthought/mayavi] Memory leak while rendering many images (#517)

@eleboss, that seems to work, thanks! Any idea why the garbage collection does not work?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

yougrianes commented 1 year ago

Mess up while using multi-processing, may because single figure is created but using clf by different thread. :-/ Put the figure code inside the loop and so far so good. :->

@solarjoe Put the figure code outside the loop, and just clear the figure not close the window. Then you will find the magic happen. ` import numpy as np from mayavi import mlab

mlab.options.offscreen=True

n = 10000 nt = 5000 fig = mlab.figure(bgcolor=(1.0, 1.0, 1.0), size=(1600, 900)) for k in range(10000):

x = np.random.rand(n)
y = np.random.rand(n)
z = np.random.rand(n)

triangles = np.random.randint(n, size=(nt, 3))

mlab.triangular_mesh(x, y, z, triangles, scalars=np.random.rand(n))

mlab.clf()

`