enthought / enthought/mayavi

Memory leak while rendering many images

Open
#517 7 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
316
Avg merge
7h 44m
Merged PRs (30d)
5

Description

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](https://user-images.githubusercontent.com/10460113/27851210-9654ca24-6159-11e7-8e35-e1e9f6cfb533.png)

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

Other things I noticed

- the issue is not present when using `mlab.options.offscreen=True`
- the window title states "Mayavi Scene #", this # being the number of the image rendered. Shouldn't this be reset to 1 since I am closing the figure after each run?
- using gc.collect() does **not** free the memory
- similar issue mentioned on [stackoverflow ](https://stackoverflow.com/questions/24201190/saving-multiple-images-in-mayavi)
- and one at [sourceforge](https://sourceforge.net/p/mayavi/mailman/message/26762146/)

Here is a working example:

```python
#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()
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.