Angular app freezes browser after some time

Viewed 6934

My angular based app freezes browser after some time. I thought it could possibly happen because of change detection so I set OnPush on the most of top-level components but browser keeps frozen after some time. I checked activity monitor on my mac and it shows me that Google Chrome Helper goes over 100% of CPU after some time and my browser dies. What could be the reason?

2 Answers

I had those problems in the past as well. Be sure to destory all subscribers properly and check if you have any webworker in the background. Those resource get filled from time to time. Make sure to destory them when the component is destoryed.

  ngOnDestroy(): void {
     this.observable.unsubscribe();
  }

This usually happens when you have an *ngIf on a component in the template or when your route is changing and the dependent components.

I came across the same problem. This problem is due to memory leakage in angular. Anyone can not find the exact reason for this, everyone have weird situations of memory leakage that freeze the browser and hang system.

You can go through the following link it might help you.

https://itnext.io/angular-rxjs-detecting-memory-leaks-bdd312a070a0

Related