FXCanvas内存泄漏

时间:2016-06-16 14:52:49

标签: javafx memory-leaks eclipse-rcp

我正在使用Eclipse e4 RCP应用程序,我有一个SWT部分。使用JavaFX与SWT的互操作性我添加了javafx.embed.swt.FXCanvas。用50000 javafx.scene.control.Button创建一个javafx.scene.Scene并将其挂钩到画布后,应用程序内存跳转到1.5gb。

当我关闭该部分时问题开始,应用程序不释放内存。当我再次打开那个部分时,内存会跳转到2.something gb。

Part class:

import javax.annotation.PostConstruct;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import javafx.embed.swt.FXCanvas;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Pane;

public class StressTestJavaFXPart
{
    private Scene scene;
    private FXCanvas canvas;

    private final int columns = 100;
    private final int rows = 500;

    @PostConstruct
    public void createComposite(final Composite parent)
    {
        parent.setLayout(new GridLayout(1, false));
        canvas = new FXCanvas(parent, SWT.NONE);
        GridDataFactory.fillDefaults().grab(true, true).span(0, 0).applyTo(canvas);

        final Pane pane = new Pane();

        for (int i = 0; i < columns ; i++)
        {
            for (int j = 0; j < rows ; j++)
            {
                final Button button = new Button(String.format("%s : %s", i, j));
                pane.getChildren().add(button);
                button.setLayoutX(100 * i);
                button.setLayoutY(100 * j);
            }
        }

        final ScrollPane sp = new ScrollPane(pane);
        scene = new Scene(sp);
        canvas.setScene(scene);

        parent.addDisposeListener(new DisposeListener()
        {
            @Override
            public void widgetDisposed(final DisposeEvent e)
            {
                canvas.dispose();
                System.gc();
            }
        });
    }
}

非常欢迎任何建议!感谢

0 个答案:

没有答案