Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-41421

Exponential memory leak in V4 Array.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P1: Critical P1: Critical
    • 5.4.0 RC
    • 5.3.2
    • None
    • Linux pc 3.16.2-1-ARCH #1 SMP PREEMPT Sat Sep 6 13:12:51 CEST 2014 x86_64 GNU/Linux

      I attached a trivial testcase to reproduce the leak.

      Short version here:

          var queue = [];
          for (var i = 0; i < 1000; i++) {
              queue.unshift(5);
              queue.splice(0, 1);
          }
      

      This code creates an array, and then adds an element to it and cuts out an array of length 1 starting from the element number 0. The last two steps are repeated 1000 times.

      V4 utilizes all available memory and crashes.

      300 iterations produce ~200 MiB memory usage for me.
      350 iterations — ~1.5 GiB.
      360 iterations — ~3.1 GiB.

      Update:

      Actually, unshift-pop produces the same behavior (memleak), unshift-shift does not.

      unshift-pop — bad
      unshift-splice — bad
      unshift-shift — ok
      push-pop — ok
      push-splice — ok
      push-shift — ok

      So, the memleak could be reproduced even with

      var queue = [];
      for (var i = 0; i < 1000; i++) {
          queue.unshift(5);
          queue.pop();
      }
      

        1. memoryCrash2.qml
          0.5 kB
        2. memoryCrash3.qml
          0.2 kB
        3. memoryCrash4.qml
          0.2 kB
        4. memoryCrash5.qml
          0.2 kB
        5. qmlleak.200.massif.out
          595 kB
        6. qmlleak.310.callgrind.out
          1.91 MB
        7. qmlleak.310.massif.out
          155 kB
        For Gerrit Dashboard: QTBUG-41421
        # Subject Branch Project Status CR V

            laknoll Lars Knoll
            chalker Сковорода Никита
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes