Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Angular/Typescript: Deep copy could lead to memory leak?

I have the following component:

@Component({
    selector: 'app-columns-list-configurations',
    templateUrl: 'columns.list.configurations.component.html'
})
export class ColumnsListConfigurationsComponent implements OnInit, OnDestroy {

    private descriptionWasChanged: EventEmitter<ATreeExpanderItem> = new EventEmitter<ATreeExpanderItem>();

    constructor() {}

    ngOnInit(): void {
        this.descriptionWasChanged.subscribe((item: ATreeExpanderItem) => {
            this.changeDescription(item as ColumnListModel);
            let localItems: Array<ColumnListModel> = this.deepCopy(this.items);
            this.itemsHasChanged(localItems);
        });
    }

    private deepCopy(columns: Array<ColumnListModel>): Array<ColumnListModel> {
        let newColumns: Array<ColumnListModel> = new Array<ColumnListModel>();
        columns.forEach((column: ColumnListModel) => {
            let newColumn: ColumnListModel = new ColumnListModel();
            newColumn.set(column, this.deepCopy(column.items as Array<ColumnListModel>));
            newColumns.push(newColumn);
        });
        return newColumns;
    }
}

itemsHasChanged(...) {...}

I have a function deepCopy that tries to make an array deep copy and I have a event subscription descriptionWasChanged that each time that is an emit is made, makes a deepCopy and passes the array copy to the itemsHasChanged function.

Could I have memory leak problems:

  1. Each time the descriptionWasChanged.subscribe finishes is work?
  2. Each time the component ColumnsListConfigurationsComponent is destroyed?

Comments