HPCToolkit / hpcviewer.e4

Eclipse 4 version of hpcviewer
Other
9 stars 0 forks source link

SWT resource leak #215

Open laksono opened 2 years ago

laksono commented 2 years ago

Describe the bug Eclipse reported a SWT resource leak in the trace view while rendering the depth view.

To Reproduce Sometimes it happens with prof2 database, but not always. The call stack reported:

java.lang.Error: SWT Resource was not properly disposed
    at org.eclipse.swt.graphics.Resource.initNonDisposeTracking(Resource.java:172)
    at org.eclipse.swt.graphics.Resource.<init>(Resource.java:120)
    at org.eclipse.swt.graphics.Image.<init>(Image.java:216)
    at edu.rice.cs.hpctraceviewer.ui.depth.DepthPaintThread.initPaint(DepthPaintThread.java:33)
    at edu.rice.cs.hpctraceviewer.ui.internal.BasePaintThread.call(BasePaintThread.java:110)
    at edu.rice.cs.hpctraceviewer.ui.internal.BasePaintThread.call(BasePaintThread.java:1)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)

Code in DepthPaintThread:

 31         protected void initPaint(/*Device device,*/ int width, int height) {
 32                 final Display device = Display.getDefault();
 33                 image = new Image(device, width, height);
 34                 gc    = new GC(image);
 35         }

If we dispose the image in DepthPaintThread:33, it will cause the problem since the DepthViewPaint is still using it:

org.eclipse.swt.SWTException: Graphic is disposed
    at org.eclipse.swt.SWT.error(SWT.java:4893)
    at org.eclipse.swt.SWT.error(SWT.java:4808)
    at org.eclipse.swt.SWT.error(SWT.java:4779)
    at org.eclipse.swt.graphics.Image.getBounds(Image.java:1017)
    at edu.rice.cs.hpctraceviewer.ui.depth.DepthViewPaint.drawPainting(DepthViewPaint.java:101)
    at edu.rice.cs.hpctraceviewer.ui.internal.BaseViewPaint.endPainting(BaseViewPaint.java:340)
    at edu.rice.cs.hpctraceviewer.ui.internal.BaseViewPaint.executePaint(BaseViewPaint.java:255)
    at edu.rice.cs.hpctraceviewer.ui.internal.BaseViewPaint.lambda$0(BaseViewPaint.java:194)
...

Code of DepthViewPaint:

 95         protected void drawPainting(ISpaceTimeCanvas canvas, ImagePosition img) {
 96                 if (masterGC != null && !masterGC.isDisposed() && img != null && img.image != null)
 97                 {
 98                         try {
 99                                 masterGC.drawImage(     img.image,  // source image
100                                                                         0, 0,           // source X and Y
101                                                                         img.image.getBounds().width, img.image.getBounds().height,      // Source width and height
102                                                                         0, Math.round(img.position * numPixels),                                                // target x and y
103                                                                         img.image.getBounds().width, img.image.getBounds().height);             // target width and height
104                         } catch (Exception e) {
105                                 e.printStackTrace();
106                         }
107                         img.image.dispose();
108                 }

The DepthPaintThread class shouldn't reuse the image variable to avoid the potential resource leak.

blue42u commented 1 year ago

This repository has moved to GitLab, please continue this issue there.