Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8044851

nashorn properties leak memory

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 9
    • 8u40
    • core-libs
    • None
    • b28
    • generic
    • generic

        Adding and removing properties to an object leaks memory. A test program (adapted from node's test/simple/test-event-emitter-memory-leak.js) follows -

        var Thread = java.lang.Thread;
        var runtime = java.lang.Runtime.getRuntime();
        var mb = 1024 * 1024;

        var noop = function() {};
        var map = {};

        runtime.gc();
        Thread.sleep(1000);
        var before = runtime.freeMemory();
        print('before ' + before / mb);
        for (var i = 0; i < 16e5; ++i) {
          var name = 'a-pretty-long-event-name-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-' + i;
          map[name] = noop;
          delete map[name];
          if ((i % 1e5) === 0) {
            runtime.gc();
            print(' ' + (runtime.freeMemory() - before) / mb);
          }
        }
        runtime.gc();
        Thread.sleep(1000);
        var after = runtime.freeMemory();
        print('after ' + after / mb);
        print('leaked ' + ((after - before) / mb));

        when run as 'jjs -J-Xms1g -J-Xmx1g leak.js' can be observed to increase its resident size steadily as the program progresses, and prints freeMemory which is seen as steadily decreasing -

        before 966.2640838623047
               7.783241271972656
               44.487510681152344
               45.94429016113281
               46.042991638183594
               45.18035125732422
               44.3046875
               43.93107604980469
               43.05583953857422
               42.19343566894531
               41.37696075439453
               40.98670196533203
               40.12110137939453
               39.256675720214844
               38.39038848876953
               37.998321533203125
               37.12486267089844
        after 1001.1347503662109
        leaked 34.87066650390625

              hannesw Hannes Wallnoefer
              akhil Akhil Arora (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: