QPA: memory leaks in platform integrations like qminimal and others
-
Goal
We would like to use QMinimal QPA for our project. We run our application on the server without any physical screens.
We also use address sanitiser to prevent memory leaks.Problem
We noticed, there are a number of memory leaks happening in plugins code.For example, there:
https://github.com/yinyunqiao/qtbase/blob/master/src/plugins/platforms/minimal/qminimalintegration.cpp#L50QMinimalIntegration::QMinimalIntegration() { QMinimalScreen *mPrimaryScreen = new QMinimalScreen(); mPrimaryScreen->mGeometry = QRect(0, 0, 240, 320); mPrimaryScreen->mDepth = 32; mPrimaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied; mScreens.append(mPrimaryScreen); }
We create pointer QMinimalScreen *mPrimaryScreen and allocate memory that will never be deallocated. The same happens in linuxfb, for example.
For some reason there's no destructor for this class.Question
- Why don't we have destructors that would free this memory?
- Is it possible to come up with some workaround, so that in our code we could do free this memory manually?
We tried to do something like
QList<QScreen*> list = QGuiApplication::screens(); for (auto screen : list) { delete screen; }
But it doesn't work, because deleting forward-declared object lead to unpredicted behaviour, and it seems there's no way to downcast it to QMinimalScreen.
-
@AnatoliyS said in QPA: memory leaks in platform integrations like qminimal and others:
But it doesn't work, because deleting forward-declared object lead to unpredicted behaviour
Can you explain this? QScreen has a virtual dtor so I don't see any problem here.
And since you instantiate QMinimalIntegration only once it's not much of a problem (although it should be fixed - please create a bug report about this).