diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadReferenceProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadReferenceProxyImpl.java index dfa1b49f310b..7b8b1d1f9df0 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadReferenceProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/ThreadReferenceProxyImpl.java @@ -38,7 +38,7 @@ public final class ThreadReferenceProxyImpl extends ObjectReferenceProxyImpl imp private String myName; private int myFrameCount = -1; // stack frames, 0 - bottom - private final List myFramesFromBottom = new ArrayList(); + private final LinkedList myFramesFromBottom = new LinkedList(); //cache build on the base of myFramesFromBottom 0 - top, initially nothing is cached private List myFrames = null; @@ -236,11 +236,11 @@ public final class ThreadReferenceProxyImpl extends ObjectReferenceProxyImpl imp } private void checkFrames(@NotNull final ThreadReference threadRef) throws EvaluateException { - if (myFramesFromBottom.size() < frameCount()) { - int count = frameCount(); + int frameCount = frameCount(); + if (myFramesFromBottom.size() < frameCount) { List frames; try { - frames = threadRef.frames(0, count - myFramesFromBottom.size()); + frames = threadRef.frames(0, frameCount - myFramesFromBottom.size()); } catch (IncompatibleThreadStateException e) { throw EvaluateExceptionUtil.createEvaluateException(e); @@ -250,11 +250,16 @@ public final class ThreadReferenceProxyImpl extends ObjectReferenceProxyImpl imp } int index = myFramesFromBottom.size() + 1; - for (ListIterator iterator = frames.listIterator(count - myFramesFromBottom.size()); iterator.hasPrevious();) { + for (ListIterator iterator = frames.listIterator(frameCount - myFramesFromBottom.size()); iterator.hasPrevious();) { myFramesFromBottom.add(new StackFrameProxyImpl(this, iterator.previous(), index)); index++; } } + else { // avoid leaking frames + while (myFramesFromBottom.size() > frameCount) { + myFramesFromBottom.removeLast(); + } + } } @Override