Details
-
Suggestion
-
Resolution: Fixed
-
P5: Not important
-
4.5.1, 4.5.2, 4.5.3, 4.6.0, 4.6.1, 4.6.2
-
None
-
677cf76340f88e0fe51c1f75aa512b6d835414ca
Description
When a new Object is inserted into a full QCache, the function trim is called to remove some unused items out of the cache.
There is a qIsDetached call that checks if the "payload" of T is shared by other objects outside the cache.
This can lead to situations where the cache can not delete any objects at all. Therefore a property switch like setDeleteDetachedObjectsOnly(bool) would be nice.
To clarify the problem here is a example:
Imagine an ImageLoader Cache which uses two QCache objects:
QCache<QFileInfo, QImage> rawImages;
QCache<QPair<QFileInfo, EffectEnum>, QImage> manipulatedImages;
The rawImagess cache contains plain, unmodified QImages just to avoid multiple reading and decoding of jpg files.
The manipulatedImages contains some images exposed to some graphic effect(soften, noise, b/w, ....)
So, the pseudocode would like this:
QImage getManipulatedImage(QFileInfo file, EffectEnum fx) {
QImage * result = manipulatedImages.object(QPair<file, fx>);
if (result==NULL) {
//image with effect fx is not cached, so we create it.
result = rawImages(file);
if (result==NULL)
//now apply the effect
switch (fx)
manipulatedImages.insert(QPair<file,fx>, QImage(*result) ); //store the manipulated image in the second cache
}
return QImage(*result);
}
And now I come to the core of the problem:
If FX_NONE is being used, then both cached contain the same QImage with the same shared data.
In this situtation neither the first nor the second cache is willing to delete the image because it is still used by the other cache.