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
- relates to
-
PYSIDE-224 SegFault due to erroneous identification of a variable as QListWidgetItem
- Closed
For Gerrit Dashboard: PYSIDE-217 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
84476,11 | Improve the 'Value' type wrapper registration | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |