@SeDi said in QQuickImageProvider - unload Images / free memory:
Hi,
who owns an image provided by QQuickImageProvider? Does it belong to the displaying QML element or to C++/the provider? Does that depend on the use of the QQIP cache?
The function signature indicating an object rather than a reference or pointer makes it clear that the provider does not own the image returned to the QML engine.
https://doc.qt.io/qt-6/qquickimageprovider.html#requestImage
QImage QQuickImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
How can I make sure that only a small number of pictures is being held in memory?
I have not found anything like a "removeImage()" method.
https://doc.qt.io/qt-6/qquickimageprovider.html#image-caching
Images returned by a QQuickImageProvider are automatically cached, similar to any image loaded by the QML engine. When an image with a "image://" prefix is loaded from cache, requestImage() and requestPixmap() will not be called for the relevant image provider. If an image should always be fetched from the image provider, and should not be cached at all, set the cache property to false for the relevant Image or BorderImage object.
So the decision is made by the consumer of the image, rather than the provider or engine. The provider can of course maintain its own private cache.
I have thought about using a QQuickImageProvider to provide hundreds of photos from C++ to QML.
I only need about 5-15 of them at a time
After their use they have to be deleted from memory, because the user may browse through loads of them and I don't want that excessive use of memory.
Does implementing the application using the framework-provided image providers result in acceptable memory usage? I would expect roughly similar consumption.