From 566be0995d184cd2c3f99d006ffb7249aeff2e57 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 10 Oct 2013 10:26:39 +0200 Subject: C++: Release more documents. - fix memory leak in find-usages - do not retain snapshot in search history - when an editor is invisible for more than 2 minutes, release the backing snapshot Retaining snapshots will retain their documents, and if done for too long, the memory consumption might grow. This is especially the case when switching to a different kit (Qt version): in that case, the new versions of headers will be indexed, while the old ones stay around. Task-number: QTCREATORBUG-5583 Task-number: QTCREATORBUG-7645 Task-number: QTCREATORBUG-9842 Change-Id: I045eda1565e0a3fa702baeffaab9c12662f90289 Reviewed-by: Erik Verbruggen Reviewed-by: Nikolai Kosjar --- src/plugins/cpptools/cpptoolseditorsupport.cpp | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/plugins/cpptools/cpptoolseditorsupport.cpp') diff --git a/src/plugins/cpptools/cpptoolseditorsupport.cpp b/src/plugins/cpptools/cpptoolseditorsupport.cpp index 631b1c1a44..e9ec1d23a0 100644 --- a/src/plugins/cpptools/cpptoolseditorsupport.cpp +++ b/src/plugins/cpptools/cpptoolseditorsupport.cpp @@ -115,6 +115,7 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor , m_textEditor(textEditor) , m_updateDocumentInterval(UpdateDocumentDefaultInterval) , m_revision(0) + , m_editorVisible(textEditor->widget()->isVisible()) , m_cachedContentsEditorRevision(-1) , m_fileIsBeingReloaded(false) , m_initialized(false) @@ -152,6 +153,13 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor connect(m_textEditor->document(), SIGNAL(reloadFinished(bool)), this, SLOT(onReloadFinished())); + connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor *)), + this, SLOT(onCurrentEditorChanged())); + m_editorGCTimer = new QTimer(this); + m_editorGCTimer->setSingleShot(true); + m_editorGCTimer->setInterval(EditorHiddenGCTimeout); + connect(m_editorGCTimer, SIGNAL(timeout()), this, SLOT(releaseResources())); + updateDocument(); } @@ -460,6 +468,30 @@ void CppEditorSupport::updateEditorNow() editorWidget->setIfdefedOutBlocks(m_editorUpdates.ifdefedOutBlocks); } +void CppEditorSupport::onCurrentEditorChanged() +{ + bool editorVisible = m_textEditor->widget()->isVisible(); + + if (m_editorVisible != editorVisible) { + m_editorVisible = editorVisible; + if (editorVisible) { + m_editorGCTimer->stop(); + QMutexLocker locker(&m_lastSemanticInfoLock); + if (!m_lastSemanticInfo.doc) + updateDocumentNow(); + } else { + m_editorGCTimer->start(EditorHiddenGCTimeout); + } + } +} + +void CppEditorSupport::releaseResources() +{ + snapshotUpdater()->releaseSnapshot(); + QMutexLocker semanticLocker(&m_lastSemanticInfoLock); + m_lastSemanticInfo = SemanticInfo(); +} + SemanticInfo::Source CppEditorSupport::currentSource(bool force) { int line = 0, column = 0; -- cgit v1.2.1