Memory leak on reload

1,662 views
Skip to first unread message

radical...@gmail.com

unread,
May 20, 2014, 11:43:47 AM5/20/14
to node-...@googlegroups.com
Hey There,

so I'm using node-webkit (version 0.9.2) a lot lately (it's awesome) and I noticed something weird. We have large game running and it takes around 100 MB (a numbers come from the task manager). Now if I use either Window.get().reload() or window.location.reload(true/false) I see a large increase in memory. Around 100 MB. So it looks like the whole DOM is still there somehow. First I thought: "Well, maybe we have some listeners that are added each time the window reloads and it keeps the DOM because of it. But no such luck. Even versions of the game that have no actual node-webkit code have this problem. Since I can't show around the code and give a direct example I tried to reproduce it with this little example:

<!DOCTYPE html>
<html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>Playground</title>
    </head>
    <body>
    <p></p>
    'tis just the test page!
    </body>
</html>
(Is there a better way to show code in emails?)

It's just a small increase, but even with this small page there is an increase in memory usage. The funny thing is, I don't use the methods here, I just use the reload button (I assume this just calls the method anyway). I'm aware that the GC is lazy so I kept a 1.5 GB version of the game (reloaded roughly 13-15 times and got no "to many listeners" exceptions) open for one hour. Nothing changed, it was reduced by maybe 50 MB. 

Now I know I could just restart the application, but that's no good for testing (especially if you have the dev tools open). Does anyone know if I'm doing something wrong here or if this is by any chance an issue in node-webkit. Testing in Chrome shows that the GC in fact collects all the garbage correctly on reload (It's a bit lazy too). 

Thanks and regards

Roger

unread,
May 21, 2014, 6:49:15 PM5/21/14
to node-...@googlegroups.com
I deal with such kind of reports in the past. It was not like a memory
leak because the memory consumption doesn't increase further if you
continue reloading. Is this the same on your side?

There are some known references in the first DOM to keep the Node running.
> --
> You received this message because you are subscribed to the Google Groups
> "node-webkit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-webkit...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Anatoly Pashin

unread,
May 21, 2014, 6:53:59 PM5/21/14
to node-...@googlegroups.com

You also can use 'dev reload' button (it's right on toolbar) instead of restarting the app. It restarts node too.

21 мая 2014 г. 2:43 пользователь <radical...@gmail.com> написал:
--

Anatoly Pashin

unread,
May 21, 2014, 6:57:54 PM5/21/14
to node-...@googlegroups.com

Way to check GC: run node-WebKit with 'expose-gc' flag and then try globals.gc()

22 мая 2014 г. 9:53 пользователь "Anatoly Pashin" <anatoly...@gmail.com> написал:

Stefan Lange

unread,
May 21, 2014, 9:22:32 PM5/21/14
to node-...@googlegroups.com
Yes the problem seems to stay not matter how much reloads I do. I just stopped at 1.5 GB. Tested it again just now to make sure. I can understand that it keeps some references, but as said each reload add around 100 MB to the RAM usage. Again I'm sorry I can't simply share the project. 

Stefan Lange

unread,
May 21, 2014, 9:27:39 PM5/21/14
to node-...@googlegroups.com
Haha, I didn't know this button did this. I always wondered since it simply reloaded the page (visually spoken). Indeed, this seems to close the nw.exe and restart correctly. Is there a way to this by code? If not it would be an awesome feature to have, since I guess not all people have the toolbar open. I use keycombos to open the dev tools and reload the page, so our game still maintains crisp pixels (We also have a debugging tools decreases the visible space even more).

Also, how do I add these flags? I tried adding expose-gc as parameter for the nw.exe, as well as "js-flags"/"chromium-args" in the package.json. There was no globals object nor a gc method.

Roger

unread,
May 21, 2014, 9:45:31 PM5/21/14
to node-...@googlegroups.com
I mean the memory consumption shouldn't increase when you reload in
the 2nd time or more. If this not the case there, please submit a case
so I can reproduce and fix here.

Anatoly Pashin

unread,
May 22, 2014, 1:45:44 AM5/22/14
to node-...@googlegroups.com
Also, how do I add these flags? I tried adding expose-gc as parameter for the nw.exe, as well as "js-flags"/"chromium-args" in the package.json. There was no globals object nor a gc method.

 "js-flags": "--expose-gc",

global.gc();
Пашин Анатолий,
эникейщик.

Stefan Lange

unread,
May 22, 2014, 6:28:51 AM5/22/14
to node-...@googlegroups.com
@Roger
I'll make an issue on the GitHub page, is that okay? Do you want an example? I can try an create a small page that creates a large object. But my minimal example in the OP already has the problem (Although with less increase per reload). It is as you said. In raises everytime. global.gc() does really nothing apart from clearing some MB. 

@Anatoly
Thanks! I accidentally added the js-flags to the window object in the package.json


--
You received this message because you are subscribed to a topic in the Google Groups "node-webkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-webkit/0vBDY7JExgo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-webkit...@googlegroups.com.

Stefan Lange

unread,
May 22, 2014, 6:42:17 AM5/22/14
to node-...@googlegroups.com
I just tested it again and my minimal example does not have the problem. Is there a list of things that are kept on reload? Like window listeners or something like this? 

Roger

unread,
May 24, 2014, 8:16:18 AM5/24/14
to node-...@googlegroups.com
Yeah. An issue report with reproducible case is welcome.

Currently I don't have the list of object kept in DOM. Previously when
I debugged the issue I found they are being used for the native UI
bindings which was developed by @zcbenz. Though the consumption
doesn't increase on 2nd reload or later, I'm sure it can be improved.

Roger

Stefan Lange

unread,
May 28, 2014, 1:28:11 PM5/28/14
to node-...@googlegroups.com
Alright I can make an issue. Problem is that the minimal example works as said. It allocates some extra memory but does not go beyond much after more reloads. Only thing I can share is that the project is made with impact.js. The engine might do some crazy stuff.
Message has been deleted

Robert Starsi

unread,
Sep 7, 2014, 9:57:24 AM9/7/14
to node-...@googlegroups.com
I had exactly the same issue with my app, during development when reloading. The memory consumption would just keep growing on each reload. I was using:

window.location.reload()

The solution was to replace that with:

require('nw.gui').Window.get().reloadDev()

`reloadDev` is described at https://github.com/rogerwang/node-webkit/wiki/Window
Message has been deleted

mag...@gmail.com

unread,
Jan 10, 2015, 7:42:46 PM1/10/15
to node-...@googlegroups.com
Hi,

I am experiencing the same issue. I am using Node-webkit to build an application using Angular-JS. When i use certain links inside my application, which load a different section of my app, i can see my memory diminish for each time a different section loads. However, when i use the DevReload (most right situated reload button), garbage is collected.

I am getting the impression this isn't supposed to be happening and Stefan Lange's minimal example doesn't show this behaviour, so then in my case it must be related to Angular-JS. Does anyone have experience with Angular-JS bogging up memory? Thanks for any pointers!

I am still working on it, but the current version is working. However to use the app one must have a Pinboard account, since i am using their API/credentials to log someone in :/

mag...@gmail.com

unread,
Jan 10, 2015, 8:13:32 PM1/10/15
to node-...@googlegroups.com, mag...@gmail.com
I have read up about Angular-JS and memory usage, implemented some tips and tricks. I have ran the very useful Timeline profiler from google dev tools, and it shows that my app uses (when i switch pages a few times, click some things, expand stuff and close it, etc. etc.) at max 101 MB. However, when I start my app with 1 GB of memory, after the profiling session i only have about 750ish MB left. 

Is this because of node-webkit also garbage collecting from time to time? Is it then usefull to manually call for garbage collection after each (major) loading operation? 
Since it takes a while before node-webkit garbage collects itself?

Thanks, Michael

re...@toteat.com

unread,
Jan 12, 2017, 8:32:54 PM1/12/17
to nw.js
Any news on this subject? I'm having serious memery leaks, we are planning to migrate to electron, tested there without leaks....

Vimal Solanki

unread,
Feb 29, 2024, 10:02:46 AMFeb 29
to nw.js
I'm facing same kind of memory leak issue in my electron app. I've used react with electronJS. I've added "window.location.reload()" method in some of the cases so whenever this code gets execute then the memory is getting increase by around 5-10 MB. In 1/2 hours is reached at 1.5 GB memory usage. Initially it takes around 100/200 MB.

Kindly be helpful.

Thanks!
Vimal Solanki.

Alex Aloia

unread,
Feb 29, 2024, 1:36:03 PMFeb 29
to Vimal Solanki, nw.js
This is an nwjs thread, not electron. 

Thank you, 

Alex Aloia 

On Feb 29, 2024, at 9:02 AM, Vimal Solanki <vi...@logicrays.com> wrote:

I'm facing same kind of memory leak issue in my electron app. I've used react with electronJS. I've added "window.location.reload()" method in some of the cases so whenever this code gets execute then the memory is getting increase by around 5-10 MB. In 1/2 hours is reached at 1.5 GB memory usage. Initially it takes around 100/200 MB.
--
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nwjs-general/1d275855-2052-4361-8533-77de332a1cfen%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages