1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 17:25:38 +02:00

Bug 420928 - Terminal widget leaks memory

Change-Id: I38f62a629f0a11e9b5dc6e33147f0ea06777bd6c
Signed-off-by: Anton Leherbauer <anton.leherbauer@windriver.com>
This commit is contained in:
Anton Leherbauer 2015-02-19 08:55:37 +01:00 committed by Uwe Stieber
parent 12f0136c24
commit 7a4a0a06bd
2 changed files with 30 additions and 11 deletions

View file

@ -38,6 +38,7 @@
* Anton Leherbauer (Wind River) - [434749] UnhandledEventLoopException when copying to clipboard while the selection is empty
* Martin Oberhuber (Wind River) - [436612] Restore Eclipse 3.4 compatibility by using Reflection
* Anton Leherbauer (Wind River) - [458398] Add support for normal/application cursor keys mode
* Anton Leherbauer (Wind River) - [420928] Terminal widget leaks memory
*******************************************************************************/
package org.eclipse.tm.internal.terminal.emulator;
@ -96,7 +97,6 @@ import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
import org.eclipse.tm.internal.terminal.provisional.api.Logger;
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
import org.eclipse.tm.internal.terminal.textcanvas.ITextCanvasModel;
import org.eclipse.tm.internal.terminal.textcanvas.PipedInputStream;
import org.eclipse.tm.internal.terminal.textcanvas.PollingTextCanvasModel;
import org.eclipse.tm.internal.terminal.textcanvas.TextCanvas;
@ -182,6 +182,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
*/
volatile private Job fJob;
private PollingTextCanvasModel fPollingTextCanvasModel;
public VT100TerminalControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors) {
this(target, wndParent, connectors, false);
}
@ -387,6 +389,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
}
disconnectTerminal();
fClipboard.dispose();
fPollingTextCanvasModel.stopPolling();
getTerminalText().dispose();
}
@ -711,8 +714,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
ITerminalTextDataSnapshot snapshot=fTerminalModel.makeSnapshot();
// TODO how to get the initial size correctly!
snapshot.updateSnapshot(false);
ITextCanvasModel canvasModel=new PollingTextCanvasModel(snapshot);
fCtlText=new TextCanvas(fWndParent,canvasModel,SWT.NONE,new TextLineRenderer(fCtlText,canvasModel));
fPollingTextCanvasModel=new PollingTextCanvasModel(snapshot);
fCtlText=new TextCanvas(fWndParent,fPollingTextCanvasModel,SWT.NONE,new TextLineRenderer(fCtlText,fPollingTextCanvasModel));
fCtlText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
fCtlText.addResizeHandler(new TextCanvas.ResizeListener() {
@ -1232,10 +1235,12 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
if(fCtlText!=null && !fCtlText.isDisposed()) {
if (isConnected()) {
fCtlText.setCursorEnabled(true);
fPollingTextCanvasModel.startPolling();
} else {
fCtlText.setCursorEnabled(false);
// Stop capturing all key events
fFocusListener.captureKeyEvents(false);
fPollingTextCanvasModel.stopPolling();
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2015 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
@ -7,6 +7,7 @@
*
* Contributors:
* Michael Scharf (Wind River) - initial API and implementation
* Anton Leherbauer (Wind River) - [420928] Terminal widget leaks memory
*******************************************************************************/
package org.eclipse.tm.internal.terminal.textcanvas;
import org.eclipse.swt.widgets.Display;
@ -17,19 +18,32 @@ import org.eclipse.tm.terminal.model.ITerminalTextDataSnapshot;
*
*/
public class PollingTextCanvasModel extends AbstractTextCanvasModel {
int fPollInterval=50;
private static final int DEFAULT_POLL_INTERVAL = 50;
int fPollInterval = -1;
/**
*
*/
public PollingTextCanvasModel(ITerminalTextDataSnapshot snapshot) {
super(snapshot);
Display.getDefault().timerExec(fPollInterval,new Runnable(){
public void run() {
update();
Display.getDefault().timerExec(fPollInterval,this);
}});
startPolling();
}
public void setUpdateInterval(int t) {
fPollInterval=t;
fPollInterval = t;
}
public void stopPolling() {
// timerExec only dispatches if the delay is >=0
fPollInterval = -1;
}
public void startPolling() {
if (fPollInterval < 0) {
fPollInterval = DEFAULT_POLL_INTERVAL;
Display.getDefault().timerExec(fPollInterval, new Runnable(){
public void run() {
update();
Display.getDefault().timerExec(fPollInterval, this);
}
});
}
}
}