Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-217

Leak in getter function generated with CppGenerator::writeGetterFunction when `newWrapperSameObject` is true

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Fixed
    • Affects Version/s: 1.2.1, 1.2.x, dev
    • Fix Version/s: dev
    • Component/s: Shiboken
    • Labels:

      Description

      The getter function generated with CppGenerator::writeGetterFunction when
      the function local variable newWrapperSameObject is true creates a new wrapper
      object on every call, resulting in memory leak

      The following code demonstrates memory leak in accessing the `format` property of QtGui.QTextEdit.ExtraSelection objects.

      from __future__ import print_function
      import psutil, os
      from PySide2 import QtWidgets, QtCore
      a = QtWidgets.QApplication([])
      tf = QtWidgets.QTextEdit.ExtraSelection()
      mem = [0]*100
      p = psutil.Process(os.getpid())
      for i in range(100):
          for j in range(1000):
              tf.format
          mem[i] = p.memory_info().rss
      print('memory leak per format access:', (mem[-1]-mem[0])/100.0/1000)
      for i in range(100):
          for j in range(1000):
              tf.cursor
          mem[i] = p.memory_info().rss
      print('memory leak per cursor access:', (mem[-1]-mem[0])/100.0/1000)
      

      Output

      memory leak per format access: 272.50688
      memory leak per cursor access: 279.59296
      

      The issue is that in the generated function `Sbk_QTextEdit_ExtraSelection_get_format` a new wrapper object is created on every access in the following line:
      `PyObject* pyOut = Shiboken::Object::newObject((SbkObjectType*)SbkPySide_QtGuiTypes[SBK_QTEXTCHARFORMAT_IDX], &(cppSelf->format), false, true);`

      I think a solution would be to first check if a binding for the cppField is already registered and return the binding in that case instead of creating new binding.

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              ctismer Christian Tismer
              Reporter:
              pankajp Pankaj Pandey
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes