-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core]: PrimeVue 4 is causing a memory leak #5957
Comments
Hello @mertsincan I just created a barebone Nuxt 3.12.2 / PrimeVue 3.52.0 project with nuxt-primevue 3.0.0 with the same logic as my reproducer and can confirm that it doesn't happen there :) I'll setup a Nuxt project without @primevue/nuxt-module quickly and report back. |
@mertsincan I was able to replicate it by just using PrimeVue 4 without the nuxt module. https://github.com/luke-z/primevue-4-memory-leak/tree/no-nuxt-module Edit: disabling ssr resolves the memory leak Edit 2: Removing the vueApp.use(PrimeVue, {
- theme: {
- preset: Aura,
- },
}); Edit 3: Registering the nuxt plugin as client only ( |
Yes it seems that primevue is causing memory leak due to some interaction with ssr. I haven't been able to find the exact source yet, but 3.52 primevue is working fine |
Thanks so much for your help, @luke-z and @RoyeL12! Can you try your cases after making the following changes? node_modules/@primevue/core/config/index.mjs // line 203
ThemeService.on('theme:change', function (newTheme) {
+ if (!isThemeChanged.value) {
+ app.config.globalProperties.$primevue.config.theme = newTheme;
+ isThemeChanged.value = true;
+ }
}); |
It seems to lower the curve, however it does not completely remove it. With my However, both cases shoot up to 1-2GB of instance size quite fast. Edit: I just noticed removing reactive from this line: primevue/packages/core/src/config/PrimeVue.js Line 169 in 9bc3954
And commenting out the entire ThemeService listener helped to keep the memory usage stable. |
Thanks @luke-z ;) I think this line in TheemService is causing all these problems;
As you said, this may be calling more than one watcher. I keep digging :) |
I figured out something more. I went into the node_modules/@primeuix/styled/index.mjs and added the following lines in createService()
right below the initialization of allHandlers. So on one hand, the reactive thing is messing with the memory and on the other hand the EventBus is not cleaning up properly. Don't know if a weakmap would help there? Adding a simple console.log('hello') to the ThemeService.on('theme:change') also shows, that with each page refresh, a new "console log" is added. So on first page load it will log "hello", then 2x, then 3x and so on |
Yes, you're right! I made some changes eventbus and config files. Could you please try; node_modules/@primeuix/styled/index.mjs // line 329
+ },
+ clear() {
+ allHandlers.clear();
+ } node_modules/@primevue/core/config/index.mjs // line 168
function setup(app, options) {
var PrimeVue = {
config: reactive(options)
};
app.config.globalProperties.$primevue = PrimeVue;
app.provide(PrimeVueSymbol, PrimeVue);
+ clearConfig();
setupConfig(app, PrimeVue);
return PrimeVue;
}
+ var stopWatchers = [];
+ function clearConfig() {
+ ThemeService.clear();
+ stopWatchers.forEach(function (fn) {
+ return fn === null || fn === void 0 ? void 0 : fn();
+ });
+ stopWatchers = [];
+ }
function setupConfig(app, PrimeVue) {
var isThemeChanged = ref(false); // line 212
ThemeService.on('theme:change', function (newTheme) {
+ if (!isThemeChanged.value) {
app.config.globalProperties.$primevue.config.theme = newTheme;
isThemeChanged.value = true;
+ }
});
/*** Watchers ***/
+ var stopConfigWatcher = watch(PrimeVue.config, function (newValue, oldValue) {...);
+ var stopRippleWatcher = watch(function () {...);
+ var stopThemeWatcher = watch(function () {...);
+ var stopUnstyledWatcher = watch(function () {...);
+ stopWatchers.push(stopConfigWatcher);
+ stopWatchers.push(stopRippleWatcher);
+ stopWatchers.push(stopThemeWatcher);
+ stopWatchers.push(stopUnstyledWatcher); |
I just applied these changes to the reproducer I attached and can confirm that the memory leak seems to be resolved! When spamming the application with the |
Great!! Thank you very much for your help! The details really helped me in solving the problem. |
Thanks for your effort! |
This problem still occurs even in the latest version |
I am also facing the same issue in primevue without SSR. Can anyone help me? |
Describe the bug
Hello
Today we discovered a memory leak caused by the primevue nuxt(-module) / SSR.
Edit: As the problem arises with the core package, I changed the title :)
It appears to be caused by two lines:
primevue/packages/core/src/config/PrimeVue.js
Line 173 in 9bc3954
primevue/packages/core/src/config/PrimeVue.js
Line 198 in 9bc3954
-> This event listener is getting registered on each page refresh without being removed. So there will be more and more instances of this event listener.
If I comment out these two lines in the compiled server.mjs and restart the nuxt server, no memory leak is happening when doing the steps mentioned in the reproduction area.
Reproducer
https://github.com/luke-z/primevue-4-memory-leak
PrimeVue version
4.0.0-rc.2
Vue version
3.x
Language
TypeScript
Build / Runtime
Nuxt
Browser(s)
No response
Steps to reproduce the behavior
yarn build
node .output/server/index.mjs
ab -n 10000 -c 100 localhost:3000/
to get fast results)Expected behavior
No memory leak
The text was updated successfully, but these errors were encountered: