WIP: Decrease Brain memory consumption#8399
WIP: Decrease Brain memory consumption#8399GuillaumeFavelier wants to merge 4 commits intomne-tools:masterfrom
Conversation
|
I wonder if Then the LookupTable / Actor is probably another (separate) problem? It's probably going to take more code commenting-out and line tracking to sort it out... |
| fig=figure) | ||
|
|
||
| if _get_3d_backend() == "pyvista": | ||
| self.plotter = self._renderer.plotter |
There was a problem hiding this comment.
Now that Brain is public we should probably make as many attributes as possible private, so _plotter is better here
|
And an automatic test would be to ensure that this list is actually empty. |
|
Those 2 are added in BackgroundPlotter: And the rest is related to our use of |
|
c2f56b5 gets rid of the ref to |
|
See also pyvista/pyvista#958 |
|
The remaining It appears in this code: import gc
import time
import numpy as np
import mne
rr, tris = mne.read_surface(mne.datasets.sample.data_path() + '/subjects/fsaverage/surf/lh.inflated')
tris = np.pad(tris, ((0, 0), (1, 0)), 'constant')
assert tris.shape[1] == 4
tris[:, 0] = 3
for _ in range(1):
brain = mne.viz.Brain('fsaverage', 'both', 'inflated')
brain.close()
del brain
time.sleep(0.1)
gc.collect()
print([o.__class__.__name__ for o in gc.get_objects() if o.__class__.__name__.startswith('vtk')], len(gc.get_objects()))But not in this one: import gc
import time
import numpy as np
import pyvista
import mne
rr, tris = mne.read_surface(mne.datasets.sample.data_path() + '/subjects/fsaverage/surf/lh.inflated')
tris = np.pad(tris, ((0, 0), (1, 0)), 'constant')
assert tris.shape[1] == 4
tris[:, 0] = 3
for _ in range(1):
brain = mne.viz.Brain('fsaverage', 'both', 'inflated')
brain.close()
del brain
time.sleep(0.1)
gc.collect()
print([o.__class__.__name__ for o in gc.get_objects() if o.__class__.__name__.startswith('vtk')], len(gc.get_objects())) |
|
@larsoner on my machine, using this script: import gc
import time
import numpy as np
import mne
rr, tris = mne.read_surface(mne.datasets.sample.data_path() + '/subjects/fsaverage/surf/lh.inflated')
tris = np.pad(tris, ((0, 0), (1, 0)), 'constant')
assert tris.shape[1] == 4
tris[:, 0] = 3
for _ in range(1):
brain = mne.viz.Brain('fsaverage', 'both', 'inflated')
brain.close()
del brain
time.sleep(0.1)
gc.collect()
print([o.__class__.__name__ for o in gc.get_objects() if o.__class__.__name__.startswith('vtk')], len(gc.get_objects()))gives: And strangely enough if I import pyvista, it disappears. I don't have an explanation for now. Can you confirm that you obtain a similar list? |
|
@GuillaumeFavelier I incorporated this into #8379 except for d597e80. Feel free to cherry-pick that one and push to my PR. Travis should fail there soon with some |
|
I'll work directly on your branch then 👍 |
The first goal is to collect all the remaining vtk objects:
mem_brain.py:
To remove:
The second goal is to improve Brain memory consumption to help with #8379
cc @larsoner