angular / angular/components

Memory Leak in Injector

Aperta
#22,292 2 commenti 2 reazioni 0 assegnatari Vedi su GitHub
area: cdk/overlay needs investigation P3
Lingua principale
TypeScript
Stelle
25k
Fork
6.8k
Merge medio
1g 8h
PR unite (30g)
91

Descrizione

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.

![1](https://user-images.githubusercontent.com/25796932/111782318-8c5e7b80-88c1-11eb-9797-ef426b18963d.PNG)
![2](https://user-images.githubusercontent.com/25796932/111782313-8b2d4e80-88c1-11eb-96a1-2790a5506f16.PNG)
![3](https://user-images.githubusercontent.com/25796932/111782316-8bc5e500-88c1-11eb-9976-c9184fad91f3.PNG)

#### 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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Il report nomina AppComponent, MyComponent, OverlayRef, Injector e ComponentPortal; inizia riproducendo clic ripetuti e controllando gli heap snapshot. Traccia il ciclo di vita attach/detach dell'overlay e i riferimenti di Injector.create, quindi verifica se l'array iniettato viene rilasciato dopo la chiusura e acquisisci il risultato in un test di regressione o in una diagnosi documentata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
frontend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.