Created
December 10, 2024 21:50
-
-
Save steph-crown/bfe6b0fb00950d4a761442f757fdc17a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
export class MemoryLeakComponent implements OnInit, OnDestroy { | |
constructor(private readonly router: Router) {} | |
count = 0; | |
private sub: Subscription | undefined; | |
ngOnInit() { | |
this.sub = interval(1000).subscribe(() => { | |
this.count++; | |
console.log('Count:', this.count); // This will keep logging as more subscriptions are created | |
}); | |
} | |
goBack() { | |
this.router.navigate(['/']); | |
} | |
ngOnDestroy() { | |
if (this.sub) { | |
this.sub.unsubscribe(); | |
} | |
console.log('Unsubscribed and cleaned up'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment