*** If you're not sure this is actually a bug, instead post about it at https://discuss.kde.org If you're reporting a crash, attach a backtrace with debug symbols; see https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports Please remove this comment after reading and before submitting - thanks! *** SUMMARY The `Krita::documents()` method returns a `QList<Document*>`. When called from a Python plugin, all the `Document*` are leaked. STEPS TO REPRODUCE 1. Open the scripter 2. Run ``` for i in range(100000): docs = Krita.instance().documents() ``` OBSERVED RESULT Heap usage rises permanently EXPECTED RESULT Heap usage stays stable SOFTWARE/OS VERSIONS Windows: macOS: (available in the Info Center app, or by running `kinfo` in a terminal window) Linux/KDE Plasma: KDE Plasma Version: KDE Frameworks Version: Qt Version: 5.15.14 ADDITIONAL INFORMATION `documents()` is defined as `QList<Document *> documents() const /Factory/;`. But a `QList<*>` cannot track ownership. `/Factory/` just communicates that the caller owns the `QList`, but `QList` cleanup won't (can't!) clean up the `Document*`s. The method should probably return a `QList<QScopedPointer<Document>>`?
Woops - forgot to remove the readme :)
We worked around it on the Python side with this helper: ``` def acquire_elements(l: list[QOBJECT]) -> list[QOBJECT]: # Many Pykrita functions return a `QList<QObject*>` where the objects are # allocated for the callee. SIP does not handle this case and just leaks # the objects outright. Fix this by taking explicit ownership of the objects. # Note: ONLY call this if you are confident that the Pykrita function # allocates the list members! for obj in l: if obj is not None: sip.transferback(obj) return l ```
You cannot add a QScopedPointer to a QList, but I'm trying to find alternative solutions...