Angular Memory Errors in Production
Angular's change detection runs frequently in production. When components hold large datasets or leak subscriptions, memory usage balloons until the browser tab crashes.
Subscription Leaks
The most common Angular memory issue. Every subscribe() must be cleaned up:
// BAD — subscription lives forever
@Component({ ... })
export class DashboardComponent implements OnInit {
ngOnInit() {
this.dataService.getUpdates().subscribe(data => {
this.items = data;
});
}
}
// GOOD — use takeUntilDestroyed or async pipe
@Component({ ... })
export class DashboardComponent {
items$ = this.dataService.getUpdates();
constructor(private dataService: DataService) {}
}<div *ngFor="let item of items$ | async">
{{ item.name }}
</div>OnPush Change Detection
Default change detection checks every component on every cycle. Switch to OnPush for data-heavy components:
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
...
})
export class TableComponent {
@Input() data: Item[];
}Virtual Scrolling for Large Lists
import { ScrollingModule } from '@angular/cdk/scrolling';<cdk-virtual-scroll-viewport itemSize="50">
<div *cdkVirtualFor="let item of items">
{{ item.name }}
</div>
</cdk-virtual-scroll-viewport>This renders only visible items, reducing DOM nodes from thousands to dozens.
Bugsly captures JavaScript heap size and component lifecycle errors in production Angular apps, helping you identify which components are responsible for memory growth.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
Fix Memory Leak in Haskell
Resolve memory leaks in Haskell caused by lazy evaluation, unevaluated thunks, and space leaks in common data structures.
Read moreReact Debugging Tips for Every Developer
Essential React debugging techniques including DevTools profiling, component re-render analysis, state inspection, and error boundary setup.
Read moreHow to Fix Query Error in Rails
Learn how to diagnose and fix the query error in Rails. Includes code examples and prevention tips.
Read moreHow to Fix Query Error in React
Learn how to diagnose and fix the query error in React. Includes code examples and prevention tips.
Read more