diff --git a/CHANGES.md b/CHANGES.md index baf54c04ab59..254e7807b962 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ - Fixed an issue with clamping of non-looped glTF animations. Subscribers to animation `update` events should expect one additional event firing as an animation stops. [#7387](https://github.com/CesiumGS/cesium/issues/7387) - Fixed a bug with very long view ranges requiring multiple frustums even with the logarithmic depth buffer enabled. Previously, such scenes could resolve depth incorrectly. [#8727](https://github.com/CesiumGS/cesium/pull/8727) - Fixed a bug where the elevation contour material's alpha was not being applied. [#8749](https://github.com/CesiumGS/cesium/pull/8749) +- Fix potential memory leak when destroying `CesiumWidget` instances. ### 1.68.0 - 2020-04-01 diff --git a/Source/Widgets/CesiumWidget/CesiumWidget.js b/Source/Widgets/CesiumWidget/CesiumWidget.js index f105dcd9923e..a5d5497caef6 100644 --- a/Source/Widgets/CesiumWidget/CesiumWidget.js +++ b/Source/Widgets/CesiumWidget/CesiumWidget.js @@ -366,7 +366,7 @@ function CesiumWidget(container, options) { 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) { @@ -374,7 +374,8 @@ function CesiumWidget(container, options) { "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."; @@ -709,7 +710,10 @@ CesiumWidget.prototype.isDestroyed = function () { * removing the widget from layout. */ CesiumWidget.prototype.destroy = function () { - this._scene = this._scene && this._scene.destroy(); + if (defined(this._scene)) { + this._scene.renderError.removeEventListener(this._onRenderError); + this._scene = this._scene.destroy(); + } this._container.removeChild(this._element); this._creditContainer.removeChild(this._innerCreditContainer); destroyObject(this);