简体   繁体   中英

SWT memory leak

I am painting images of a Canvas with a GC (of course) but after I had repainted a new frame with new imaged I need to delete the previous but I don't know how.

I want to dispose the data on the canvas and then redraw the frame but I don't know how. Anyone knows how can I dispose the data on the canvas without disposing the canvas itself?

You don't have to dispose of the old data on the Canvas , just use GC.fillRectangle to fill the canvas with the background color in your paint listener.

Something like:

@Override
public void paint(final PaintEvent event)
{
  Rectangle clientArea = getClientArea();

  GC gc = event.gc;

  gc.setBackground(getBackground());

  gc.fillRectangle(clientArea);

  ... draw your new data
}

I have fixed it guys, thank you all! The problem was that I was creating new Images but wasn't disposing them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM