From 55d54c7e978fceda999a53cfcd9132fe2496a086 Mon Sep 17 00:00:00 2001 From: "JiaLi.Passion" Date: Mon, 12 Feb 2018 08:35:20 +0900 Subject: [PATCH] fix(platform-browser): fix #22155, destroy hammer manager when off (#22156) PR Close #22156 --- .../platform-browser/src/dom/events/hammer_gestures.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/platform-browser/src/dom/events/hammer_gestures.ts b/packages/platform-browser/src/dom/events/hammer_gestures.ts index 7e2a5db227..d6136ff8a1 100644 --- a/packages/platform-browser/src/dom/events/hammer_gestures.ts +++ b/packages/platform-browser/src/dom/events/hammer_gestures.ts @@ -71,6 +71,7 @@ export const HAMMER_LOADER = new InjectionToken('HammerLoader'); export interface HammerInstance { on(eventName: string, callback?: Function): void; off(eventName: string, callback?: Function): void; + destroy?(): void; } /** @@ -214,7 +215,13 @@ export class HammerGesturesPlugin extends EventManagerPlugin { zone.runGuarded(function() { handler(eventObj); }); }; mc.on(eventName, callback); - return () => mc.off(eventName, callback); + return () => { + mc.off(eventName, callback); + // destroy mc to prevent memory leak + if (typeof mc.destroy === 'function') { + mc.destroy(); + } + }; }); }