Skip to content

Commit 4ca16d7

Browse files
crisbetokara
authored andcommitted
fix(snack-bar): leaking object references (#4403)
Fixes #2942.
1 parent 078aa19 commit 4ca16d7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/lib/snack-bar/snack-bar-container.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,13 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
111111
}
112112

113113
if (event.toState === 'visible') {
114+
// Note: we shouldn't use `this` inside the zone callback,
115+
// because it can cause a memory leak.
116+
const onEnter = this.onEnter;
117+
114118
this._ngZone.run(() => {
115-
this.onEnter.next();
116-
this.onEnter.complete();
119+
onEnter.next();
120+
onEnter.complete();
117121
});
118122
}
119123
}
@@ -152,9 +156,13 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
152156
* errors where we end up removing an element which is in the middle of an animation.
153157
*/
154158
private _completeExit() {
159+
// Note: we shouldn't use `this` inside the zone callback,
160+
// because it can cause a memory leak.
161+
const onExit = this.onExit;
162+
155163
this._ngZone.onMicrotaskEmpty.first().subscribe(() => {
156-
this.onExit.next();
157-
this.onExit.complete();
164+
onExit.next();
165+
onExit.complete();
158166
});
159167
}
160168
}

0 commit comments

Comments
 (0)