mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-03 15:15:25 +02:00
Bug 367417 - IndexerPreferenceListener leaks CEditor instance
This commit is contained in:
parent
6755ff6b79
commit
ccf30980da
2 changed files with 24 additions and 4 deletions
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -12,6 +12,7 @@
|
||||||
package org.eclipse.cdt.ui.tests.text;
|
package org.eclipse.cdt.ui.tests.text;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
@ -110,8 +111,8 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CEditor fEditor;
|
private CEditor fEditor;
|
||||||
private static SourceViewer fSourceViewer;
|
private SourceViewer fSourceViewer;
|
||||||
private ICProject fCProject;
|
private ICProject fCProject;
|
||||||
private IProject fNonCProject;
|
private IProject fNonCProject;
|
||||||
private StyledText fTextWidget;
|
private StyledText fTextWidget;
|
||||||
|
@ -443,6 +444,24 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
assertTrue(part instanceof CEditor);
|
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.
|
* Type characters into the styled text.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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>. */
|
/** The translation unit that was added by the editor to index, or <code>null</code>. */
|
||||||
private ITranslationUnit fTuAddedToIndex;
|
private ITranslationUnit fTuAddedToIndex;
|
||||||
|
|
||||||
private IndexerPreferenceListener fIndexerPreferenceListener;
|
private final IndexerPreferenceListener fIndexerPreferenceListener;
|
||||||
|
|
||||||
private static final Set<String> angularIntroducers = new HashSet<String>();
|
private static final Set<String> angularIntroducers = new HashSet<String>();
|
||||||
static {
|
static {
|
||||||
|
@ -2200,6 +2200,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
fIndexerPreferenceListener.unregister();
|
||||||
updateIndexInclusion(null, true);
|
updateIndexInclusion(null, true);
|
||||||
|
|
||||||
ISourceViewer sourceViewer = getSourceViewer();
|
ISourceViewer sourceViewer = getSourceViewer();
|
||||||
|
|
Loading…
Add table
Reference in a new issue