angular / angular/components

Memory Leak in Injector

Đang mở
#22,292 2 bình luận 2 reaction 0 người được giao Xem trên GitHub
area: cdk/overlay needs investigation P3
Ngôn ngữ chính
TypeScript
Star
25k
Fork
6.8k
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
91

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Báo cáo nêu AppComponent, MyComponent, OverlayRef, Injector và ComponentPortal; hãy bắt đầu bằng cách tái hiện các lần nhấp lặp lại và kiểm tra heap snapshots. Theo dõi vòng đời attach/detach của overlay và các tham chiếu của Injector.create, sau đó xác nhận liệu mảng được inject có được giải phóng sau khi dismissal hay không, rồi ghi lại kết quả trong một regression test hoặc một chẩn đoán được lập tài liệu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, typescript
Lĩnh vực
frontend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.