Instantiating C++ objects from QML has tremendous memory usage overhead

280 views Asked by At

Instantiating a QObject derived class on the heap in C++ gives me roughly about 160 bytes per object.

Registering the same object via qmlRegisterType() for creation from QML and creating the object dynamically via createObject() gives me a little over 2000 bytes per object.

That's quite the difference, almost 13 times more memory per object is being used when creating from QML. Note that the object doesn't have any bindings or anything extra compared to how it is in C++.

Naturally, being QObject derived means it is a non-visible object. So it shouldn't have any extra overhead as far as scene-graph rendering is concerned.

Note that I have ran tests with a significant amount of objects multiple times, getting consistent results and scaling up proportionally, so it is unlikely that it is due to some variance or QML engine memory pre-allocation.

Why is that happening? Is it normal? Is there a way to reduce it?

0

There are 0 answers