Skip to content

Conversation

pmoleri
Copy link
Contributor

@pmoleri pmoleri commented Mar 26, 2025

When a TemplateOutlet instance was being destroyed all its locally cached views were not being destroyed.

The parent component (grid) was attempting to clean up all the template outlets on the its destroy. But, this approach is weak because TemplateOutlets could have been destroyed along the way (resize, groupby, etc), so all those caches would have never been destroyed.

The new strategy:

  • uniquely identified views (templateID.id) are meant to be managed by the parent component, so now the parent component destroys them directly and the template outlet never caches them locally.
  • other templates (local) are destroyed by the template outlet destroy.

Example bug scenario in the old code:

  • Grid renders 20 rows
  • Group by is run, some of the template outlets change to summary template, detaching their old row viewref which is kept in the cache.
  • Then, some operation removes templates outlets, e.g. grid resize, page size change, filter data.
  • Those template-outlet instances get destroyed but .destroy() is not called on their cached/detached views. Angular still holds a reference to them permanently.
  • Grid gets destroyed. The remaining template-outlet instances are cleaned up correctly. But previous undestroyed ones are still lingering.

Repro:

  • Go to: https://pmoleri.github.io/grid-leak/grid
  • Don't open the devtools yet
  • Drag "Title" column to group by it
  • Change page size to 5
  • Click on "Show" chekbox to destroy the grid
  • Open Devtools
  • In Memory tab Take a snapshot
  • Select "Object retained by detached DOM nodes"
  • See the leaked <igx-grid-row> elements

Note that this repro is based on 19.1.5 which doesn't contain other fixes. So, you'll find also other leaks.

Additional information (check all that apply):

  • Bug fix
  • New functionality
  • Documentation
  • Demos
  • CI/CD

Checklist:

  • All relevant tags have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them

When a TemplateOutlet instance was being destroyed all
its locally cached views were not being destroyed.

The parent component (grid) was attempting to clean up all the template outlets
on the its destroy. But, this approach is weak because TemplateOutlets could
have been destroyed along the way (resize, groupby, etc),
so all those caches would have never been destroyed.

The new strategy:
 * uniquely identified views (templateID.id) are meant to be managed by the
   parent component, so now the parent component destroys them directly and the
   template outlet never caches them locally.
 * other templates (local) are destroyed by the template outlet destroy.
@pmoleri pmoleri marked this pull request as ready for review March 27, 2025 12:01
@kdinev kdinev requested review from ChronosSF and kdinev April 15, 2025 12:53
@ChronosSF ChronosSF changed the base branch from master to 20.0.x June 9, 2025 12:03
Copy link

github-actions bot commented Aug 9, 2025

There has been no recent activity and this PR has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label Aug 9, 2025
@ChronosSF ChronosSF removed the status: inactive Used to stale issues and pull requests label Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants