Inspection: Lost SWT controls

Questions about YourKit Java Profiler
Post Reply
Mark Christiaens
Posts: 1
Joined: Wed Mar 11, 2020 2:18 pm

Inspection: Lost SWT controls

Post by Mark Christiaens »

I suspect that the inspection "Lost SWT controls" is not behaving as hoped. The help message mentions:
Technically, it finds instances of org.eclipse.swt.widgets.Control which are not accessible from org.eclipse.swt.widgets.Display's field 'controlTable'.
On Linux, there is no field 'controlTable' in Display.java. It is only present in the win32 version of Display.java. Indeed, when I run this analysis on a heap dump of an Eclipse application, it seems to report back that all SWT controls are lost. When I analyse one of those controls in detail, I see that there are paths from the Display object down to the control. These paths seem to start from the 'widgetTable' field in Display.

Another thing I expected was that this analysis would take the 'isDisposed' state into account. When a control is disposed, I suspect it is fine that it is not accessible from Display anymore. The only thing left to do with the control is garbage collection. I would think that only controls that are not reachable from Display and are not disposed should be reported?
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Inspection: Lost SWT controls

Post by Anton Katilin »

Hello Mark,

Thank for pointing this out.

The inspection was created many years ago and has not been reviewed since then.

We'll investigate.

Best regards,
Anton
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Inspection: Lost SWT controls

Post by Anton Katilin »

Hello Mark,

> When a control is disposed, I suspect it is fine that it is not accessible from Display anymore.
Agree.

> The only thing left to do with the control is garbage collection.
Agree.

> I would think that only controls that are not reachable from Display and are not disposed should be reported?
Do you suggest to report only non-disposed controls, but never report a control which has been disposed?

But if a control is not reachable from Display, disposed, but still reachable from anywhere else i.e. cannot be collected, wouldn't that control be a leak? Are there any cases when it makes sense to keep a disposed control in memory?

Another question (I'm not very much familiar with SWT, we use AWT/Swing): is it technically possible that a control is removed from Display (not reachable from it) but is not disposed?

Best regards,
Anton
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Inspection: Lost SWT controls

Post by Anton Katilin »

Update: next build will handle "widgetTable" and therefore solve the problem with Linux snapshots.
Post Reply