Skip to content

Conversation

cocarmon
Copy link
Contributor

@cocarmon cocarmon commented May 15, 2025

New Pull Request

This PR fixes the issue of the memory leak described in #5028 .

Each time the screen is resized, a new chart is created and added to the global Apex._chartInstances array. However, old chart instances were not being cleaned up on window resize, which led to a significant increase in memory usage over multiple resizes.

I extracted the logic used in the ApexCharts class’s destroy() method to remove old chart instances, moved it into a private method (_removeOldChartInstance()), and now call that method from both update() and destroy().

Fixes #5028

Below is a comparison of the memory after resizing the window 7 times. After multiple tests the average is a ~97% reduction in memory usage.

Before:

After:

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • My branch is up to date with any changes from the main branch

@junedchhipa
Copy link
Contributor

@cocarmon Can you create a codepen for the issue where _chartInstances is not being cleared during resize?
When I logged _chartInstances during resize, it's always being cleared.

@cocarmon
Copy link
Contributor Author

This fixes the memory leak, but only because it nukes the _chartinstances which isn't ideal as they aren't repopulated on every resize. I'm starting a new job soon so I have had limited amount of time to dedicate to this, I will look more into it though.

Copy link

github-actions bot commented Aug 9, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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.

Memory Leak When Using responsive Option in Charts on Extreme Resize
2 participants