angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.37k stars 6.75k forks source link

virtual-scroll: call component hooks when attached/detached #16324

Open aalbericio opened 5 years ago

aalbericio commented 5 years ago

Feature Description

Call specific hooks on components/renderers that are "attached" or "detached" from the virtual scroll rendering zone to gain full control on "destroying" or "re-creating" a renderer.

Use Case

Virtual scroll is a great feature inside the CDK but due to its core nature of reusing component instances, it may cause memory leaks in not-so complex renderers.

Imagine a renderer (component) initializes some subscriptions at constructor/init level (of course, we added an OnDestroy handler to remove them once the component is destroyed). Due to the native feature for recycling component instances of the virtual-scroll, this OnDestroy method may not be called unless the container is destroyed.

It would be useful to have some kind of "hook" (in the component livecycle hook) that we could implement to properly control all these possible memory leaks due to component recycling.

If I'm not wrong, virtual-scroll internally "attaches" or "detaches" components so it could be enough to have a OnAttach or OnDetach or, since this is a custom feature of virtual-scroll and we don't want to interfere into these framework hooks, any other specific hook.

angular-robot[bot] commented 2 years ago

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

angular-robot[bot] commented 2 years ago

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.