Windows: Limit cursor cache.

Prevent the cursor cache from growing indefinitely hitting GDI resource
limits if new pixmap cursors are created repetitively by purging out
all-noncurrent pixmap cursors.

Change-Id: I4a3bbd6235af13e306ca84ac6fea3fcd69d53279
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
bb10
Friedemann Kleint 2014-12-08 13:58:13 +01:00
parent 9ccd359be8
commit a6436ff559
1 changed files with 14 additions and 1 deletions

View File

@ -570,8 +570,21 @@ QWindowsWindowCursor QWindowsCursor::pixmapWindowCursor(const QCursor &c)
{
const QWindowsCursorCacheKey cacheKey(c);
CursorCache::iterator it = m_cursorCache.find(cacheKey);
if (it == m_cursorCache.end())
if (it == m_cursorCache.end()) {
if (m_cursorCache.size() > 50) {
// Prevent the cursor cache from growing indefinitely hitting GDI resource
// limits if new pixmap cursors are created repetitively by purging out
// all-noncurrent pixmap cursors (QTBUG-43515)
const HCURSOR currentCursor = GetCursor();
for (it = m_cursorCache.begin(); it != m_cursorCache.end() ; ) {
if (it.key().bitmapCacheKey && it.value().handle() != currentCursor)
it = m_cursorCache.erase(it);
else
++it;
}
}
it = m_cursorCache.insert(cacheKey, QWindowsWindowCursor(c));
}
return it.value();
}