You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Memory leak : callbacks in EventBus are never removed
Description
A memory leak issue exists due to the EventBus. Some callback functions registered to the EventBus 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
Go to official website
Navigate to a component page.
Switch to another component page.
Repeat steps 2 and 3 several times.
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 how config and config.ripple watchers register listeners on PrimeVueService without cleanup:
consthandleWatch=(el)=>{constwatchers=el.$instance?.watch;// for 'config'watchers?.['config']?.call(el.$instance,el.$instance?.$primevueConfig);PrimeVueService.on('config:change',({ newValue, oldValue })=>watchers?.['config']?.call(el.$instance,newValue,oldValue));// for 'config.ripple'watchers?.['config.ripple']?.call(el.$instance,el.$instance?.$primevueConfig?.ripple);PrimeVueService.on('config:ripple:change',({ newValue, oldValue })=>watchers?.['config.ripple']?.call(el.$instance,newValue,oldValue));};
Similarly, _loadStyles registers listeners for theme changes but does not remove them:
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
The text was updated successfully, but these errors were encountered: