1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-03 07:05:24 +02:00

Bug 367417 - IndexerPreferenceListener leaks CEditor instance

This commit is contained in:
Anton Leherbauer 2011-12-23 10:24:43 +01:00
parent 6755ff6b79
commit ccf30980da
2 changed files with 24 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -12,6 +12,7 @@
package org.eclipse.cdt.ui.tests.text;
import java.io.File;
import java.lang.ref.WeakReference;
import java.net.URI;
import java.net.URISyntaxException;
@ -110,8 +111,8 @@ public class BasicCEditorTest extends BaseUITestCase {
}
}
private static CEditor fEditor;
private static SourceViewer fSourceViewer;
private CEditor fEditor;
private SourceViewer fSourceViewer;
private ICProject fCProject;
private IProject fNonCProject;
private StyledText fTextWidget;
@ -443,6 +444,24 @@ public class BasicCEditorTest extends BaseUITestCase {
assertTrue(part instanceof CEditor);
}
public void testLeakingInstanceAfterClose() throws Exception {
final String file= "/ceditor/src/main.cpp";
fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false, false);
setUpEditor(file);
fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
WeakReference<CEditor> ref = new WeakReference<CEditor>(fEditor);
EditorTestHelper.closeEditor(fEditor);
fEditor = null;
fSourceViewer = null;
int ngc = 10;
while (ref.get() != null && ngc-- > 0) {
System.gc();
Thread.sleep(200);
}
assertNull("CEditor instance seems to be leaking after close", ref.get());
}
/**
* Type characters into the styled text.
*

View file

@ -1400,7 +1400,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
/** The translation unit that was added by the editor to index, or <code>null</code>. */
private ITranslationUnit fTuAddedToIndex;
private IndexerPreferenceListener fIndexerPreferenceListener;
private final IndexerPreferenceListener fIndexerPreferenceListener;
private static final Set<String> angularIntroducers = new HashSet<String>();
static {
@ -2200,6 +2200,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
*/
@Override
public void dispose() {
fIndexerPreferenceListener.unregister();
updateIndexInclusion(null, true);
ISourceViewer sourceViewer = getSourceViewer();