Memory Leak in Injector
- Vorherrschende Sprache
- TypeScript
- Sterne
- 25k
- Forks
- 6.8k
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 91
Beschreibung
I've encountered a possible memory leak while using `OverlayRef` and `Injector`.
#### Reproduction
Inside `AppComponent` there is a click event on a button. That click event will generate an array and pass that array to another component using `ComponentPortal`
The constructor and the click event from `AppComponent`:
```
// ? AppComponent constructor
constructor(private overlay: Overlay) {
this.#overlayRef = this.overlay.create({
positionStrategy: this.overlay
.position()
.global()
.centerHorizontally()
.centerVertically(),
hasBackdrop: true,
});
this.#overlayRef.backdropClick().subscribe(() => this.#overlayRef.detach());
}
onClick(){
const output = new Array(1000).fill('asfasdf');
this.#overlayRef.attach(
new ComponentPortal(
MyComponent,
null,
Injector.create({
providers: [{ provide: MY_TOKEN, useValue: output }],
})
)
);
}
```
#### Actual Behavior
It looks like each time the modal is created the data generated and injected in the component, but once the modal disappears, the data is not removed from the memory.



#### Environment
- Angular:
- "@angular/core": "~11.2.5",
- CDK/Material:
- "@angular/cdk": "^11.2.4",
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): Windows10
Beitragsleitfaden
Rechercherichtung
Der Bericht nennt AppComponent, MyComponent, OverlayRef, Injector und ComponentPortal. Beginne damit, wiederholte Klicks zu reproduzieren und Heap-Snapshots zu prüfen. Verfolge den attach/detach-Lebenszyklus des Overlays und die Verweise von Injector.create. Bestätige anschließend, ob das injizierte Array nach dem Schließen freigegeben wird, und halte das Ergebnis in einem Regressionstest oder einer dokumentierten Diagnose fest.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- angular, typescript
- Bereich
- frontend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100