Is there a limit on the number of QT objects you can have in the Workbench?

Hi I am trying to write a new reduction GUI for the Workbench in Python with Qt5 and I am running in some strange problem.
I have a QTreeView which should show a Tree of Scans, it is filled by a custom QAbstractItemModel.
This is working fine as long as I have less than around 10.000 objects in the Tree, if I have more I get an error:
“RuntimeError: wrapped C/C++ object of type QSpinBox has been deleted”
on the next QtObject which comes after filling the Model.
It does not seem to be a Garbage collection problem, since I can change the QtObject to anything and I get the same error (even on objects that will have a reference for sure like the QSpinBox).

Before I sub-classed QAbstractItemModel I used QStandardItemModel.
I had the same problem, but earlier since I had a lot of QStandardItems.
This was running fine outside of Mantid, even with much more Objects.

It also does not matter if I do incremental filling of the model, or fill it completely at creation.

So I am wondering if there is anything special in the Workbench that limits the number of QtObjects?

I could probably write something with uses fetchmore to get less objects, but that would prevent the user from being able to select all items.

I am not aware of anything like that in place.

I’ve seen this error pop up whenever the widget has been garbage collected by Python, but I am not sure why it would only happen with a high number of widgets.

Does it happen earlier if you run the GC manually? Say, add 1000 objects, do

import gc

Additionally, does it happen with GC disabled?

import gc

Another question: does your hierarchy change in any way between running it standalone and in Workbench? What is the parent of the your main widget in each case?

If you have a fork of the Github repo with your work on it, I could have a look

Thanks for your help.
You are right, it is a garbage collection problem. Somehow my whole window gets garbage collected, I checked the list of the collected objects.
It just appears at high numbers because garbage collection is triggered.
If it is turned off it works.
Something seems to be wrong right at the creation of the Mainwindow object, because this is in the garbage collection:
<DNSReduction.DNSReductionGUI.DNSReductionGUI object at 0x000000002EBC7CA8>
the instance is created here:

and the class is defined here:

Thank you for your response.

After a discussion with the team, we believe the issue is on our end.
You shouldn’t need to change anything in your code.

We are looking into this now, and I will keep you up to date.

PR is open here: Added interface execution enviroment as class property by Matthew-Andrew · Pull Request #25607 · mantidproject/mantid · GitHub, after it’s merged into master, you will have to merge master into your branch to get the change.

Ok, nice. Thanks for your help.

Hi Thomas, the PR has been merged into master, you should be able to get the changes now. Could you try it out and see if your issue still persists?