question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nwjs seems to leak memory via tray menu items

See original GitHub issue

NWJS Version : v0.30.1 Operating System : macOS 10.13.4. Other platforms might be affected as well.

The documentation is not explicit about how a tray/menu should be refreshed/manipulated after creation. However, I have tried the following approaches that all seem to result in increasing memory usage:

  1. Simply reassigning tray.menu a new Menu object that contains new MenuItem objects
  2. Using menu.removeAt() to remove all menu items before adding new ones
  3. Using tray.remove(), creating a new Tray object, then assigning a new Menu object
  4. Approaches 2 and 3 combined

Expected behavior

Memory usage should not grow indefinitely as the tray menu is refreshed.

Actual behavior

Memory usage continues to grow as the tray menu is refreshed.

How to reproduce

<!DOCTYPE html>
<html>
  <head>
    <title>Hi</title>
  </head>
  <body style="width: 100%; height: 100%;">
    <script>
      const tray = new nw.Tray({ title: 'Tray' });

      setInterval(() => {
        const menu = new nw.Menu();

        menu.append(new nw.MenuItem({ type: 'normal', label: 'A' }));
        menu.append(new nw.MenuItem({ type: 'normal', label: 'B' }));
        menu.append(new nw.MenuItem({ type: 'normal', label: 'C' }));

        tray.menu = menu;
      }, 10)
    </script>
  </body>
</html>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:27 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
rogerwangcommented, May 2, 2018

Yes. Probably in a week.

On Wed, May 2, 2018 at 10:11 PM Jake Douglas notifications@github.com wrote:

Thank you! Will this be in a release soon?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/nwjs/nw.js/issues/6583#issuecomment-385991199, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKGGU2u1-gng75WvSNVIRYKKWcxWrgKks5tub5-gaJpZM4TkTTw .

0reactions
rogerwangcommented, May 14, 2018

I agree with you that 1GB memory consumption is big but this is from an extreme benchmark that allocating objects every 10ms. The real world application may or may not behave like this. Note that the default v8 behavior on this is tuned for trade-off between garbage collection throughput, latency, and memory consumption. See more information here: https://v8project.blogspot.com/2016/10/fall-cleaning-optimizing-v8-memory.html

And it can always be tuned for your use case with appropriate js-flags for smaller memory footprint.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - nwjs seems to leak memory via tray menu items -
nwjs seems to leak memory via tray menu items. ... The documentation is not explicit about how a tray/menu should be refreshed/manipulated after...
Read more >
nwjs/nw.js - Gitter
hi i would like to create a node webkit app that would work both on win32 and win64 it eill check using command...
Read more >
Flush all memory on reload in NW.js - Stack Overflow
I made another simple app with only a couple of variables, and the same memory leak appeared when reload. I tried the NW.js...
Read more >
Tray - NW.js Documentation
The reason is that the tray and even the web page will be garbage collected by JS engine after navigation to prevent memory...
Read more >
RMMV tips: Upgrade NWJS and Chromium 67,68 64bits
We go here to see for the beginner how to update nwjs ... the 64bits version will unlock you very higth performance memory...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found