Skip to content

Fix some causes of memorr leaks#2874

Merged
lucafoscili merged 1 commit into
developfrom
feat/cleanup-stylesheet-cache
Jun 25, 2026
Merged

Fix some causes of memorr leaks#2874
lucafoscili merged 1 commit into
developfrom
feat/cleanup-stylesheet-cache

Conversation

@stefanolanari

Copy link
Copy Markdown
Collaborator

This pull request focuses on improving the cleanup and lifecycle management of dynamically positioned UI elements in several Ketchup components. The main changes ensure that all event listeners and DOM references are properly removed when components are disconnected or elements are no longer needed, preventing memory leaks and orphaned DOM nodes. The changes also introduce more reliable tracking and removal of scroll event listeners for dynamic positioning.

Dynamic Positioning and Cleanup Improvements:

  • Added explicit calls to dynamicPosition.stop() and dynamicPosition.unregister() for dynamically positioned elements (such as cards, menus, and panels) in kup-card and kup-data-table during component teardown to ensure proper cleanup. [1] [2] [3] [4] [5]
  • Updated the KupDynamicPosition.unregister() method to remove detached elements from the global container, sever object references (like originalPath and anchor), and clear the kupDynamicPosition property, aiding garbage collection and preventing orphaned DOM nodes.
  • Improved the way scroll event listeners are managed: when adding listeners, the code now tracks which ancestor elements actually received scroll listeners via a new scrollListenerTargets property, ensuring reliable and leak-free removal during cleanup. [1] [2]

Codebase Consistency:

  • Updated imports to include the KupDynamicPositionElement type where needed, ensuring type safety and consistency.

Interactable Cleanup:

  • In kup-box, extended the cleanup of interactable elements during disconnect to include touch interactions, not just drag and drop.

Ensure dynamic-position listeners and detached overlays are fully cleaned up when components disconnect or unregister. This also tracks attached scroll targets so teardown can reliably remove the exact listeners that were added.
@lucafoscili lucafoscili merged commit 98edb46 into develop Jun 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants