diff --git a/java/debugger/openapi/src/com/intellij/debugger/SourcePosition.java b/java/debugger/openapi/src/com/intellij/debugger/SourcePosition.java index 965452b70408..ce8c831a75f3 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/SourcePosition.java +++ b/java/debugger/openapi/src/com/intellij/debugger/SourcePosition.java @@ -32,6 +32,7 @@ import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.ref.WeakReference; import java.util.List; /** @@ -59,7 +60,7 @@ public abstract class SourcePosition implements Navigatable{ @NotNull private final PsiFile myFile; private long myModificationStamp = -1L; - private PsiElement myPsiElement; + private WeakReference myPsiElementRef; private Integer myLine; private Integer myOffset; @@ -120,7 +121,7 @@ public abstract class SourcePosition implements Navigatable{ myModificationStamp = myFile.getModificationStamp(); myLine = null; myOffset = null; - myPsiElement = null; + myPsiElementRef = null; } } @@ -128,7 +129,7 @@ public abstract class SourcePosition implements Navigatable{ if (myModificationStamp != myFile.getModificationStamp()) { return true; } - final PsiElement psiElement = myPsiElement; + final PsiElement psiElement = myPsiElementRef != null ? myPsiElementRef.get() : null; return psiElement != null && !ApplicationManager.getApplication().runReadAction(new Computable() { @Override public Boolean compute() { @@ -158,10 +159,13 @@ public abstract class SourcePosition implements Navigatable{ @Override public PsiElement getElementAt() { updateData(); - if (myPsiElement == null) { - myPsiElement = calcPsiElement(); + PsiElement element = myPsiElementRef != null ? myPsiElementRef.get() : null; + if (element == null) { + element = calcPsiElement(); + myPsiElementRef = new WeakReference(element); + return element; } - return myPsiElement; + return element; } protected int calcLine() {