Here is the code snippet in Angular 9:
employee.component.ts
name:string;
arr = [];
ngOnInit() {
this.name = "abc";
for (let i = 0; i < 1000; i++) {
this.arr.push(i);
}
}
When moving to another component using Angular routing, the employee component will be destroyed.
Should I clear the array and name property on ngOnDestroy() method to avoid memory leaks?
ngOnDestroy() {
this.name = "";
this.arr = [];
}
Will Angular automatically clear the array and properties on ngOnDestroy?