indicator mem leak

This commit is contained in:
Alexey Kudravtsev
2015-08-27 15:56:39 +03:00
parent ed69ae7721
commit ff085f0e70
4 changed files with 9 additions and 26 deletions
@@ -182,7 +182,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
highlight.run();
progress.checkCanceled();
HighlightingSession highlightingSession = HighlightingSessionImpl.getHighlightingSession(file, progress);
PostHighlightingVisitor highlightingVisitor = new PostHighlightingVisitor(file, document, refCountHolder, highlightingSession);
PostHighlightingVisitor highlightingVisitor = new PostHighlightingVisitor(file, document, refCountHolder);
highlightingVisitor.collectHighlights(file, holder, progress);
}
});
@@ -73,7 +73,6 @@ class PostHighlightingVisitor {
@NotNull private final Project myProject;
private final PsiFile myFile;
@NotNull private final Document myDocument;
@NotNull private final HighlightingSession myHighlightingSession;
private boolean myHasRedundantImports;
private int myCurrentEntryIndex;
@@ -94,19 +93,19 @@ class PostHighlightingVisitor {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (myProject.isDisposed() || !myFile.isValid()) return;
if (myProject.isDisposed() || !myFile.isValid() || !myFile.isWritable()) return;
IntentionAction optimizeImportsFix = QuickFixFactory.getInstance().createOptimizeImportsFix(true);
if (optimizeImportsFix.isAvailable(myProject, null, myFile) && myFile.isWritable()) {
if (optimizeImportsFix.isAvailable(myProject, null, myFile)) {
optimizeImportsFix.invoke(myProject, null, myFile);
}
}
});
}
};
Disposer.register(myHighlightingSession, invokeFixLater);
Disposer.register((DaemonProgressIndicator)progress, invokeFixLater);
if (progress.isCanceled()) {
Disposer.dispose(invokeFixLater);
Disposer.dispose(myHighlightingSession);
Disposer.dispose((DaemonProgressIndicator)progress);
progress.checkCanceled();
}
}
@@ -114,9 +113,7 @@ class PostHighlightingVisitor {
PostHighlightingVisitor(@NotNull PsiFile file,
@NotNull Document document,
@NotNull RefCountHolder refCountHolder,
@NotNull HighlightingSession highlightingSession) throws ProcessCanceledException {
myHighlightingSession = highlightingSession;
@NotNull RefCountHolder refCountHolder) throws ProcessCanceledException {
myProject = file.getProject();
myFile = file;
myDocument = document;
@@ -15,7 +15,6 @@
*/
package com.intellij.codeInsight.daemon.impl;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
@@ -24,7 +23,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
public interface HighlightingSession extends Disposable {
public interface HighlightingSession {
@NotNull Project getProject();
@NotNull PsiFile getPsiFile();
Editor getEditor();
@@ -24,7 +24,6 @@ import com.intellij.openapi.editor.ex.RangeHighlighterEx;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiDocumentManager;
@@ -48,7 +47,6 @@ public class HighlightingSessionImpl implements HighlightingSession {
@NotNull private final Project myProject;
private final Document myDocument;
private final Map<TextRange,RangeMarker> myRanges2markersCache = new THashMap<TextRange, RangeMarker>();
private volatile boolean myDisposed;
private HighlightingSessionImpl(@NotNull PsiFile psiFile,
@Nullable Editor editor,
@@ -60,10 +58,6 @@ public class HighlightingSessionImpl implements HighlightingSession {
myEditorColorsScheme = editorColorsScheme;
myProject = psiFile.getProject();
myDocument = PsiDocumentManager.getInstance(myProject).getDocument(psiFile);
Disposer.register(progressIndicator, this);
if (progressIndicator.isCanceled()) {
Disposer.dispose(progressIndicator); //dispose both progress indicator and this session in case we managed to register after indicator dispose to avoid mem leaks
}
}
private static final Key<ConcurrentMap<PsiFile, HighlightingSession>> HIGHLIGHTING_SESSION = Key.create("HIGHLIGHTING_SESSION");
@@ -159,7 +153,7 @@ public class HighlightingSessionImpl implements HighlightingSession {
@NotNull TextRange priorityRange,
@NotNull TextRange restrictedRange,
int groupId) {
myAddHighlighterInEDTQueue.offer(new Info(info, priorityRange, restrictedRange, groupId));
myAddHighlighterInEDTQueue.offer(new Info(info, restrictedRange, groupId));
}
void queueDisposeHighlighter(@Nullable RangeHighlighterEx highlighter) {
@@ -167,20 +161,13 @@ public class HighlightingSessionImpl implements HighlightingSession {
myDisposeHighlighterInEDTQueue.offer(highlighter);
}
@Override
public void dispose() {
myDisposed = true;
}
private static class Info {
@NotNull private final HighlightInfo myInfo;
@NotNull private final TextRange myPriorityRange;
@NotNull private final TextRange myRestrictRange;
private final int myGroupId;
public Info(@NotNull HighlightInfo info, @NotNull TextRange priorityRange, @NotNull TextRange restrictRange, int groupId) {
private Info(@NotNull HighlightInfo info, @NotNull TextRange restrictRange, int groupId) {
myInfo = info;
myPriorityRange = priorityRange;
myRestrictRange = restrictRange;
myGroupId = groupId;
}