Open YannisJustine opened 2 weeks ago
https://github.com/primefaces/primeuix/blob/main/packages/utils/src/eventbus/index.ts#L35
using slice and map together is slow...
it will not affect the memory leak but this could be better so use handlers.forEach((handler) => handler(evt));
instead.
Thanks a lot for your report! I'll check and get back to you.
I'm seeing the same problem. Version 4.0.7
Removing PrimeVue components causes the leak to disappear or become negligible
Describe the bug
Memory leak : callbacks in EventBus are never removed
Description
A memory leak issue exists due to the
EventBus
. Some callback functions registered to theEventBus
are never removed, causing unused callbacks to accumulate in memory over time. This leads to increased memory usage, especially in applications where components with registered callbacks are frequently added and removed.Steps to Reproduce
Before
After
Expected Behavior
When a component is destroyed or unmounted, the associated callbacks registered to the
EventBus
should be removed automatically.Actual Behavior
Callbacks registered with
EventBus.on()
are never removed, even after the component is unmounted. This causes memory leaks.Examples of Affected Code
The following code samples demonstrate instances within PrimeVue where callbacks are registered to
EventBus
without being properly removed, contributing to memory leaks:BaseDirective.js
In the
BaseDirective.js
file, the following code snippet shows howconfig
andconfig.ripple
watchers register listeners onPrimeVueService
without cleanup:Similarly,
_loadStyles
registers listeners for theme changes but does not remove them:BaseComponent.vue
In
BaseComponent.vue
, thedt
watcher registers a _themeChangeListener that is never removed:There are additional instances throughout the code with similar issues, where listeners are registered but not removed after component unmounting.
Proposed Solution
Remove callbacks from
EventBus
when the component is unmounted or destroyed.This issue is a generalization of the memory leak reported in issue #6223
Reproducer
https://primevue.org
PrimeVue version
4.2.0
Vue version
4.x
Language
TypeScript
Build / Runtime
Vue CLI App
Browser(s)
No response