Skip to content

Fix: Resolve memory leaks and improve menu update reliability#129

Merged
DBuit merged 7 commits into
DBuit:masterfrom
Pixelobserver:master
Jul 22, 2025
Merged

Fix: Resolve memory leaks and improve menu update reliability#129
DBuit merged 7 commits into
DBuit:masterfrom
Pixelobserver:master

Conversation

@Pixelobserver

Copy link
Copy Markdown
Contributor

Hello,

This pull request addresses several critical issues in the sidebar-card related to memory leaks and unreliable state updates. The changes ensure that the card is more performant, stable, and robust, especially in dynamic environments where views are frequently changed.

Key Fixes and Improvements:

1. Resolved Critical Memory Leaks

  • The Problem: The original code registered setInterval timers (for the clock and date) and global window event listeners but never cleaned them up. When the card was removed from the DOM (e.g., by navigating to another view), these timers and listeners would continue to run in the background, consuming memory and CPU resources.
  • The Solution:
    • Implemented the connectedCallback() and disconnectedCallback() lifecycle methods to properly manage resources.
    • Interval IDs are now stored in class properties (_clockInterval, _dateInterval).
    • All timers are cleared using clearInterval() and event listeners are properly removed with removeEventListener() inside disconnectedCallback(), preventing any resource leaks.

2. More Reliable Active Menu State

  • The Problem: The logic for highlighting the active menu item was tied to unreliable click event listeners on paper-tab elements and a direct call within the _menuAction() method. This could fail if navigation was triggered by other means and could lead to race conditions.
  • The Solution:
    • The menu state update is now exclusively handled by listening to the global location-changed event. This is a far more robust and centralized approach that correctly reflects the application's current path.
    • The location-changed event handler is bound to the component instance in the constructor to ensure the correct this context.
    • The redundant _updateActiveMenu() call has been removed from the _menuAction handler.

3. General Code Structure

  • Introduced new internal properties to manage timers and bound event handlers cleanly.
  • Incremented the card version to 0.1.9.7.0 to reflect these important fixes.

These changes significantly improve the stability and performance of the sidebar-card. Thank you for considering this contribution!

@Diamondback2010

Copy link
Copy Markdown

Good work! Looks like the original author is not super active anymore, maybe time for a fork?

@Pixelobserver

Copy link
Copy Markdown
Contributor Author

Yeah, unfortunately it seems the original owner has gone quiet. Let’s give it a bit more time and hope they come back – but if not, I’d be happy to help get this back on track.

@DBuit

DBuit commented Jul 22, 2025

Copy link
Copy Markdown
Owner

Great work, i will merged the changes. Thank you for your work

@DBuit DBuit merged commit 23dd3fd into DBuit:master Jul 22, 2025
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.

3 participants