Memory JFrame平滑调整内存泄漏的大小

Memory JFrame平滑调整内存泄漏的大小,memory,resize,jframe,memory-leaks,Memory,Resize,Jframe,Memory Leaks,对于我正在处理的某个GUI项目,我有一个JFrame,其中包含一个带有选项卡的窗格等等。对于每个选项卡,它都有不同的大小,因此我想将窗口调整到该大小,但我不想通过调用setSize来捕捉到该大小,我希望它更平滑地滑动到该大小。 我通过以下基本代码实现了这一点: private class Resizer implements Runnable { private int nw, nh, runs, sizex, sizey; private float width, h

对于我正在处理的某个GUI项目,我有一个JFrame,其中包含一个带有选项卡的窗格等等。对于每个选项卡,它都有不同的大小,因此我想将窗口调整到该大小,但我不想通过调用setSize来捕捉到该大小,我希望它更平滑地滑动到该大小。 我通过以下基本代码实现了这一点:

    private class Resizer implements Runnable {

    private int nw, nh, runs, sizex, sizey;
    private float width, height, wpms, hpms, decay = 0.994f;
    private Future future;

    public Resizer(int newwidth, int newheight){

        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        sizex = d.width;
        sizey = d.height;
        width = frame.getWidth();
        height = frame.getHeight();
        wpms = (float)(newwidth - frame.getWidth()) / 1000;
        wpms *= 6;
        hpms = (float)(newheight - frame.getHeight()) / 1000;
        hpms *= 6;
        nw = newwidth;
        nh = newheight;
        runs = 0;

    }

    public void run(){

        runs++;
        if (runs == 1000){

            frame.setSize(nw, nh);
            future.cancel(true);
            canResize = true;
            return;

        }

        width += wpms;
        wpms *= decay;
        height += hpms;
        hpms *= decay;
        if (height + frame.getY() > sizey)
            frame.setLocation(frame.getX(), frame.getY() - (int)(frame.getY() + height - sizey));
        frame.setSize((int) width, (int) height);
        frame.repaint();

    }

    public void setFuture(Future f){

        future = f;

    }

}

public boolean resizeTo(int width, int height){

    if (canResize){

        canResize = false;
        Resizer r = new Resizer(width, height);
        r.setFuture(timer.scheduleAtFixedRate(r, 0, 2, TimeUnit.MILLISECONDS));
        return true;

    }
    return false;

}
但有一个问题,显然是内存泄漏,在调整几次大小后,内存从20k泄漏到150k,我发现这是由于在调整大小时多次使用setSize造成的

有没有办法修复泄漏或调整大小