From 0f07b25d12fae6495080c614dd453bc9e193d7c4 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 2 Sep 2024 12:22:41 +0200 Subject: [PATCH] fix(material/badge): resolve memory leak (#29676) The badge had an extra unnecessary check which meant that it would sometimes leak memory through the style loader. This isn't a big deal on the client since there's usually only one app on the page, but it can be a problem on the server which can create and destroy an app for each request. Note that this is no longer an issue in 19.x where we use the common style loader, but we need to backport the fix to 18.x. Fixes https://github.com/angular/angular/issues/57529. --- src/material/badge/badge.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/material/badge/badge.ts b/src/material/badge/badge.ts index 74789e31d8cc..0bf93ecded3b 100644 --- a/src/material/badge/badge.ts +++ b/src/material/badge/badge.ts @@ -173,9 +173,7 @@ export class MatBadge implements OnInit, OnDestroy { appRef.onDestroy(() => { badgeApps.delete(appRef); - if (badgeApps.size === 0) { - componentRef.destroy(); - } + componentRef.destroy(); }); }