virtual-scroll: call component hooks when attached/detached #16324
Labels
area: cdk/scrolling
feature
This issue represents a new feature or feature request rather than a bug or bug fix
P3
An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
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.
The text was updated successfully, but these errors were encountered: