Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWT resource leak #215

Open
laksono opened this issue Jun 10, 2022 · 1 comment
Open

SWT resource leak #215

laksono opened this issue Jun 10, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@laksono
Copy link
Member

laksono commented Jun 10, 2022

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.

@laksono laksono added the bug Something isn't working label Jun 10, 2022
@blue42u
Copy link
Contributor

blue42u commented Aug 18, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants