Skip to content

Commit 3b4d9dc

Browse files
JiaLiPassionjasonaden
authored andcommitted
fix(platform-browser): fix #22155, destroy hammer manager when off (#22156)
PR Close #22156
1 parent 8c6c2fc commit 3b4d9dc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/platform-browser/src/dom/events/hammer_gestures.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export const HAMMER_LOADER = new InjectionToken<HammerLoader>('HammerLoader');
7171
export interface HammerInstance {
7272
on(eventName: string, callback?: Function): void;
7373
off(eventName: string, callback?: Function): void;
74+
destroy?(): void;
7475
}
7576

7677
/**
@@ -214,7 +215,13 @@ export class HammerGesturesPlugin extends EventManagerPlugin {
214215
zone.runGuarded(function() { handler(eventObj); });
215216
};
216217
mc.on(eventName, callback);
217-
return () => mc.off(eventName, callback);
218+
return () => {
219+
mc.off(eventName, callback);
220+
// destroy mc to prevent memory leak
221+
if (typeof mc.destroy === 'function') {
222+
mc.destroy();
223+
}
224+
};
218225
});
219226
}
220227

0 commit comments

Comments
 (0)