From 4aa6bdf72b53591f6b0e52d5561a2f7a77d6d85d Mon Sep 17 00:00:00 2001 From: jony89 Date: Wed, 5 Feb 2020 13:47:32 +0200 Subject: [PATCH] fix: memory leak event error is not unsubscribing the event listener to scene `renderError` is only subscribing. causing memory leak upon cesium `.destory()` --- Source/Widgets/CesiumWidget/CesiumWidget.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Widgets/CesiumWidget/CesiumWidget.js b/Source/Widgets/CesiumWidget/CesiumWidget.js index d7fb8d9e5f6b..575dbf357f54 100644 --- a/Source/Widgets/CesiumWidget/CesiumWidget.js +++ b/Source/Widgets/CesiumWidget/CesiumWidget.js @@ -333,14 +333,15 @@ import getElement from '../getElement.js'; this.targetFrameRate = options.targetFrameRate; var that = this; - scene.renderError.addEventListener(function(scene, error) { + this._onRenderError = function(scene, error) { that._useDefaultRenderLoop = false; that._renderLoopRunning = false; if (that._showRenderLoopErrors) { var title = 'An error occurred while rendering. Rendering has stopped.'; that.showErrorPanel(title, undefined, error); } - }); + } + scene.renderError.addEventListener(this._onRenderError); } catch (error) { if (showRenderLoopErrors) { var title = 'Error constructing CesiumWidget.'; @@ -671,6 +672,9 @@ import getElement from '../getElement.js'; * removing the widget from layout. */ CesiumWidget.prototype.destroy = function() { + if (this._scene) { + this._scene.renderError.removeEventListener(this._onRenderError); + } this._scene = this._scene && this._scene.destroy(); this._container.removeChild(this._element); this._creditContainer.removeChild(this._innerCreditContainer);