Skip to content

Commit 686d984

Browse files
author
Martin Luessi
committed
FIX: memory leak when calling add_data in loop
1 parent 1655e0f commit 686d984

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

surfer/viz.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def add_data(self, array, min=None, max=None, thresh=None,
768768
colormap="RdBu_r", alpha=1,
769769
vertices=None, smoothing_steps=20, time=None,
770770
time_label="time index=%d", colorbar=True,
771-
hemi=None):
771+
hemi=None, remove_existing=True):
772772
"""Display data from a numpy array on the surface.
773773
774774
This provides a similar interface to add_overlay, but it displays
@@ -817,6 +817,8 @@ def add_data(self, array, min=None, max=None, thresh=None,
817817
If None, it is assumed to belong to the hemipshere being
818818
shown. If two hemispheres are being shown, an error will
819819
be thrown.
820+
remove_existing : bool
821+
Remove surface added by previous "add_data" call.
820822
"""
821823
hemi = self._check_hemi(hemi)
822824

@@ -895,6 +897,11 @@ def add_data(self, array, min=None, max=None, thresh=None,
895897
data['surfaces'] = surfs
896898
data['colorbars'] = bars
897899
data['orig_ctable'] = ct
900+
901+
if remove_existing and self.data_dict[hemi] is not None:
902+
for surf in self.data_dict[hemi]['surfaces']:
903+
surf.parent.parent.remove()
904+
898905
self.data_dict[hemi] = data
899906

900907
def add_annotation(self, annot, borders=True, alpha=1, hemi=None,

0 commit comments

Comments
 (0)