Commit 5812ecc2 authored by Samuel Jones's avatar Samuel Jones
Browse files

Re #30308 Fix memory leak in slice viewer of ADS Observer

parent e75b3862
......@@ -44,10 +44,7 @@ class SliceViewerADSObserver(AnalysisDataServiceObserver):
self.observeRename(True)
def __del__(self):
self.observeClear(False)
self.observeDelete(False)
self.observeReplace(False)
self.observeRename(False)
self.observeAll(False)
@_catch_exceptions
def clearHandle(self):
......
......@@ -162,14 +162,15 @@ class PeaksViewerCollectionPresenter:
"""
self._view = view
self._child_presenters = []
self._ads_observer = None
self.setup_ads_observer()
# Setup ADS observer
self._ads_observer = SliceViewerADSObserver(self.replace_handle, self.rename_handle, self.clear_handle,
self.delete_handle)
def setup_ads_observer(self):
if self._ads_observer is None:
self._ads_observer = SliceViewerADSObserver(self.replace_handle, self.rename_handle, self.clear_handle,
self.delete_handle)
def close_called(self):
self._view = None
self._child_presenters = []
def clear_observer(self):
self._ads_observer = None
@property
......@@ -182,6 +183,7 @@ class PeaksViewerCollectionPresenter:
:param name: The name of a PeaksWorkspace.
:returns: The child presenter
"""
self.setup_ads_observer()
presenter = PeaksViewerPresenter(self._create_peaksviewer_model(name),
self._view.append_peaksviewer())
self._child_presenters.append(presenter)
......@@ -219,6 +221,7 @@ class PeaksViewerCollectionPresenter:
Remove the named workspace from display. No op if no workspace can be found with that name
:param name: The name of a workspace
"""
self.setup_ads_observer()
child_presenters = self._child_presenters
presenter_to_remove = None
for child in child_presenters:
......@@ -241,6 +244,7 @@ class PeaksViewerCollectionPresenter:
def notify(self, event):
"""Dispatch notification to all subpresenters"""
self.setup_ads_observer()
for presenter in self._child_presenters:
presenter.notify(event)
......
......@@ -396,6 +396,8 @@ class SliceViewer(ObservingPresenter):
def clear_observer(self):
self.ads_observer = None
if self._peaks_presenter is not None:
self._peaks_presenter.clear_observer()
# private api
def _create_peaks_presenter_if_necessary(self):
......@@ -447,7 +449,3 @@ class SliceViewer(ObservingPresenter):
def _close_view_with_message(self, message: str):
self.view.emit_close() # inherited from ObservingView
self._logger.warning(message)
def close_called(self):
if self._peaks_presenter is not None:
self._peaks_presenter.close_called()
......@@ -611,5 +611,6 @@ class SliceViewerView(QWidget, ObservingView):
def _on_rename(self, new_title):
self.setWindowTitle(new_title)
def closeEvent(self, _):
self.presenter.close_called()
def closeEvent(self, event):
super().closeEvent(event)
self.presenter.clear_observer()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment