Skip to content

Commit 17a0f5d

Browse files
fix(positioning): prevent memory leak in positioning service
PositioningService is listening to events in the constructor but it never got cleaned up on destroy. Since we can have many instances of that service, it could pile up and use more and more memory.
1 parent eaccf82 commit 17a0f5d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/positioning/positioning.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Injectable, ElementRef, RendererFactory2, Inject, PLATFORM_ID, NgZone } from '@angular/core';
2+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
23
import { isPlatformBrowser } from '@angular/common';
34

45
import { positionElements } from './ng-positioning';
56

67
import { fromEvent, merge, of, animationFrameScheduler, Subject, Observable } from 'rxjs';
78
import { Options } from './models';
89

9-
1010
export interface PositioningOptions {
1111
/** The DOM element, ElementRef, or a selector string of an element which will be moved */
1212
element?: HTMLElement | ElementRef | string;
@@ -64,7 +64,7 @@ export class PositioningService {
6464
this.update$$
6565
);
6666

67-
this.triggerEvent$.subscribe(() => {
67+
this.triggerEvent$.pipe(takeUntilDestroyed()).subscribe(() => {
6868
if (this.isDisabled) {
6969
return;
7070
}

0 commit comments

Comments
 (0)