Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 9ce2862

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(panel): destroy the scope when the panelRef is destroyed
The panel wasn't destroying its' scope within the `destroy` method, causing potential memory leaks. Fixes #8845. Closes #8848
1 parent bfad5e4 commit 9ce2862

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/components/panel/demoBasicUsage/script.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ function PanelDialogCtrl(mdPanelRef) {
9292

9393

9494
PanelDialogCtrl.prototype.closeDialog = function() {
95-
this._mdPanelRef && this._mdPanelRef.close().then(function() {
95+
var panelRef = this._mdPanelRef;
96+
97+
panelRef && panelRef.close().then(function() {
9698
angular.element(document.querySelector('.demo-dialog-open-button')).focus();
99+
panelRef.destroy();
97100
});
98101
};
99102

src/components/panel/panel.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ angular
245245
* @ngdoc method
246246
* @name MdPanelRef#close
247247
* @description
248-
* Hides and detaches the panel.
248+
* Hides and detaches the panel. Note that this will **not** destroy the panel. If you
249+
* don't intend on using the panel again, call the {@link MdPanelRef#destroy destroy} method
250+
* afterwards.
249251
*
250252
* @returns {!angular.$q.Promise} A promise that is resolved when the panel is
251253
* closed.
@@ -963,6 +965,7 @@ MdPanelRef.prototype.detach = function() {
963965
* Destroys the panel. The Panel cannot be opened again after this.
964966
*/
965967
MdPanelRef.prototype.destroy = function() {
968+
this._config.scope.$destroy();
966969
this._config.locals = null;
967970
};
968971

src/components/panel/panel.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ describe('$mdPanel', function() {
141141
expect(panelRef._config.locals).toEqual(null);
142142
});
143143

144+
it('destroy should destroy the panel scope', function () {
145+
openPanel(DEFAULT_CONFIG);
146+
147+
expect(panelRef._config.scope.$$destroyed).toBe(false);
148+
149+
panelRef.destroy();
150+
151+
expect(panelRef._config.scope.$$destroyed).toBe(true);
152+
});
153+
144154
describe('promises logic:', function() {
145155
var config;
146156

0 commit comments

Comments
 (0)