Commit ae949b9d21470a9b9bf200774c246a0b86a69ff6
QPixmapCache:Remove the old pixmap if you insert one with the same key.
If you insert a new pixmap in the cache with a key that was already in
the cache then we remove the old pixmap and add the new one. This avoid
to fill the memory with garbage even if the cache has a protection to
avoid running out of memory. This was discovered with QraphicsView
and its cache. We don't need to keep old cached pixmaps for an item.
Task-number: KDE
Reviewed-by: Trond
| |   |
| 187 | 187 | cacheKeys.insert(key, cacheKey); |
| 188 | 188 | return true; |
| 189 | 189 | } |
| qint64 oldCacheKey = cacheKeys.value(key, -1); |
| //If for the same key we add already a pixmap we should delete it |
| if (oldCacheKey != -1) |
| QCache<qint64, QDetachedPixmap>::remove(oldCacheKey); |
|
| 190 | 195 | bool success = QCache<qint64, QDetachedPixmap>::insert(cacheKey, new QDetachedPixmap(pixmap), cost); |
| 191 | 196 | if (success) { |
| 192 | 197 | cacheKeys.insert(key, cacheKey); |
| |   |
| 166 | 166 | QVERIFY(estimatedNum - 1 <= num <= estimatedNum + 1); |
| 167 | 167 | QPixmap p3; |
| 168 | 168 | QPixmapCache::insert("null", p3); |
|
| QPixmap c1(10, 10); |
| c1.fill(Qt::yellow); |
| QPixmapCache::insert("custom", c1); |
| QVERIFY(!c1.isDetached()); |
| QPixmap c2(10, 10); |
| c2.fill(Qt::red); |
| QPixmapCache::insert("custom", c2); |
| //We have deleted the old pixmap in the cache for the same key |
| QVERIFY(c1.isDetached()); |
| 169 | 179 | } |
| 170 | 180 | |
| 171 | 181 | void tst_QPixmapCache::remove() |