Bug 563018 - Make SWT Colors no longer require disposal
Summary: Make SWT Colors no longer require disposal
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.16   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.16 RC1   Edit
Assignee: Jonah Graham CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks: 563560
  Show dependency tree
 
Reported: 2020-05-10 16:50 EDT by Jonah Graham CLA
Modified: 2020-05-26 08:51 EDT (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonah Graham CLA 2020-05-10 16:50:10 EDT
The current implementation of Color in SWT does not actually require disposal of the Color instances in practice as no OS resources are allocated, so nothing to dispose.

I believe the Color requiring disposal was an artifact of limited color depth displays that no longer exist in practice anymore. This appears to be what https://www.eclipse.org/articles/Article-SWT-Color-Model/swt-color-model.htm written in 2001 says. 

I think SWT has exceeded the original use cases envisioned in that design document, specifically: "a certain number of fixed colors are decided upon for usage in the plug-in". 

Would SWT team accept a patch that removed the dispose requirement from the API doc? And/or add setBackground(RGB)/setForeground(RGB) to GC?

This came up while I was working on Bug 540737 which is to add 24-bit color support to the Terminal. Managing the resources that I am supposed to dispose of is non-trivial and in practice unneeded.
Comment 1 Alexander Kurtakov CLA 2020-05-12 16:17:25 EDT
I think this is fine idea. Sravan, what do you think?
Comment 2 Sravan Kumar Lakkimsetti CLA 2020-05-13 01:24:23 EDT
(In reply to Alexander Kurtakov from comment #1)
> I think this is fine idea. Sravan, what do you think?

I Think its a very good idea. If a patch is provided I will review it for Mac.
Comment 3 Jonah Graham CLA 2020-05-13 18:03:06 EDT
I am working on a gerrit.
Comment 4 Jonah Graham CLA 2020-05-13 19:53:30 EDT
I pushed a series of gerrits (162993-162998)

The first one (https://git.eclipse.org/r/#/c/162993/) covers just javadoc changes to document that disposal is not required. 

The rest add new constructors and do other documentation fixes. I will apply the changes to all three platforms for the rest of the commits once someone has had a first look at them to make sure I am on the correct track.
Comment 5 Lars Vogel CLA 2020-05-14 02:00:32 EDT
I suggest to add this also to the N&N. Obviously we did not know about this, as we use dispose almost everywhere for colors
Comment 6 Jens Lideström CLA 2020-05-14 11:17:35 EDT
A consequence of this change is that it will never be possible in the future to change the implementation so that Color once again requires disposal, should such a need arise. That would break backwards compatibility.

Is this something that has been considered and deemed to be an acceptable?

Also, is there any chance that there are SWT implementations for non-standard platforms, implemented by third parties, which require Color to be disposed, and would break with this change?

If these issues have been considered and accepted I think it sounds like a nice simplification.
Comment 7 Jens Lideström CLA 2020-05-14 11:23:42 EDT
(In reply to Jonah Graham from comment #4)
> I pushed a series of gerrits (162993-162998)

I'd just like to give you a tip about the "topic" feature in Gerrit:

https://gerrit-review.googlesource.com/Documentation/user-upload.html#topic

It might be useful to mark all Gerrit changes with the same topic in situations like this:

git push ssh://john.doe@git.example.com:29418/kernel/common HEAD:refs/for/experimental -o topic=color-dispose
Comment 8 Lars Vogel CLA 2020-05-14 17:00:06 EDT
Thanks, Jonah
Comment 9 Jonah Graham CLA 2020-05-14 17:03:45 EDT
Thanks Lars for merging. What should I do with the remaining commits, should I create a separate bug?
Comment 10 Lars Vogel CLA 2020-05-14 17:15:26 EDT
(In reply to Jonah Graham from comment #9)
> Thanks Lars for merging. What should I do with the remaining commits, should
> I create a separate bug?

Please cc me in the Gerrits
Comment 11 Jonah Graham CLA 2020-05-14 18:42:33 EDT
(In reply to Jens Lideström from comment #6)
> A consequence of this change is that it will never be possible in the future
> to change the implementation so that Color once again requires disposal,
> should such a need arise. That would break backwards compatibility.
> 
> Is this something that has been considered and deemed to be an acceptable?
> 
> Also, is there any chance that there are SWT implementations for
> non-standard platforms, implemented by third parties, which require Color to
> be disposed, and would break with this change?
> 
> If these issues have been considered and accepted I think it sounds like a
> nice simplification.

Thanks for raising these questions. I don't know answers myself.
Comment 12 Jonah Graham CLA 2020-05-14 18:46:02 EDT
(In reply to Lars Vogel from comment #10)
> (In reply to Jonah Graham from comment #9)
> > Thanks Lars for merging. What should I do with the remaining commits, should
> > I create a separate bug?
> 
> Please cc me in the Gerrits

Done. 

Note that the remaining Gerrits are not ready, see comment 4.
Comment 13 Jonah Graham CLA 2020-05-14 19:14:57 EDT
(In reply to Jonah Graham from comment #11)
> (In reply to Jens Lideström from comment #6)
> > A consequence of this change is that it will never be possible in the future
> > to change the implementation so that Color once again requires disposal,
> > should such a need arise. That would break backwards compatibility.
> > 
> > Is this something that has been considered and deemed to be an acceptable?
> > 
> > Also, is there any chance that there are SWT implementations for
> > non-standard platforms, implemented by third parties, which require Color to
> > be disposed, and would break with this change?
> > 
> > If these issues have been considered and accepted I think it sounds like a
> > nice simplification.
> 
> Thanks for raising these questions. I don't know answers myself.

In trying to answer some of these questions, I can start with what was said in Bug 546835 that removed the last of the actual need for disposal:

(Nikita Nemkin from Bug 546835 comment #8)
> On 256-bit color displays (which are completely obsolete), everything will
> be drawn with a reduced palette.
> On 16-bit and 32-bit color displays (which is the norm), nothing will change.

As for other implementations of SWT, is this a theoretical problem, or are there any known implementations of SWT, and if so are they active?
Comment 14 Jonah Graham CLA 2020-05-14 19:31:08 EDT
Added missing xrefs to gerrit (see Bug 563149 for why it wasn't automatic)
Comment 15 Jonah Graham CLA 2020-05-14 20:17:59 EDT
(In reply to Jens Lideström from comment #7)
> I'd just like to give you a tip about the "topic" feature in Gerrit:

Thanks for the tip - https://git.eclipse.org/r/#/q/topic:color-dispose+(status:open+OR+status:merged)
Comment 16 Jens Lideström CLA 2020-05-15 06:44:55 EDT
(In reply to Jonah Graham from comment #13)
> As for other implementations of SWT, is this a theoretical problem, or are
> there any known implementations of SWT, and if so are they active?

I remember that I have at some point heard about such things, but I don't know.

I don't have much knowledge about this, but I don't think it will be an issue. I don't think there are any active such projects. I guess that the regular SWT developers will know if it where a problem.

I found this project after a quick net search:

http://swtswing.sourceforge.net/main/index.html

It implements SWT with a Swing backend. It hasn't been updated since 2007 though.
Comment 17 Nikita Nemkin CLA 2020-05-17 11:00:30 EDT
Reopening, since there are 5 outstanding patches linked to this bug.

I think we shouldn't deprecate old Color constructors, that's a lot of new warnings for little gain. We can't stop inheriting from Resource and can't deprecate dispose() anyway.

Also, to preserve existing behavior, any Colors created and returned by SWT should have a Device reference (i.e. use an old constructor).

(In reply to Jens Lideström from comment #6)
> A consequence of this change is that it will never be possible in the future
> to change the implementation so that Color once again requires disposal,
> should such a need arise. That would break backwards compatibility.

I doubt it will ever come to this, but finalizers and reference queues are always an option.

> Also, is there any chance that there are SWT implementations for
> non-standard platforms, implemented by third parties, which require Color to
> be disposed, and would break with this change?

3rd party implementations (of which there are none in use) shouldn't prevent SWT evolution.
Comment 18 Lakshmi P Shanmugam CLA 2020-05-18 07:55:33 EDT
(In reply to Jens Lideström from comment #16)
> (In reply to Jonah Graham from comment #13)
> > As for other implementations of SWT, is this a theoretical problem, or are
> > there any known implementations of SWT, and if so are they active?
> 
> I remember that I have at some point heard about such things, but I don't
> know.
> 
> I don't have much knowledge about this, but I don't think it will be an
> issue. I don't think there are any active such projects. I guess that the
> regular SWT developers will know if it where a problem.
> 
> I found this project after a quick net search:
> 
> http://swtswing.sourceforge.net/main/index.html
> 
> It implements SWT with a Swing backend. It hasn't been updated since 2007
> though.

The other SWT ports were listed in the SWT website, but that content has been archived now as the ports are no longer active - https://www.eclipse.org/swt/archived_content.html
Comment 19 Eclipse Genie CLA 2020-05-18 14:31:16 EDT
New Gerrit change created: https://git.eclipse.org/r/163204
Comment 20 Jonah Graham CLA 2020-05-18 14:33:19 EDT
(In reply to Nikita Nemkin from comment #17)
> Reopening, since there are 5 outstanding patches linked to this bug.
> 
> I think we shouldn't deprecate old Color constructors, that's a lot of new
> warnings for little gain. We can't stop inheriting from Resource and can't
> deprecate dispose() anyway.
> 
> Also, to preserve existing behavior, any Colors created and returned by SWT
> should have a Device reference (i.e. use an old constructor).

I believe I have addressed the above concerns.

Once the patches[1] have been reviewed I will apply the same changes to the other ports.

[1] https://git.eclipse.org/r/q/topic:%2522color-dispose%2522+status:open
Comment 21 Jens Lideström CLA 2020-05-18 15:11:22 EDT
(In reply to Nikita Nemkin from comment #17)
> Reopening, since there are 5 outstanding patches linked to this bug.
> 
> I think we shouldn't deprecate old Color constructors, that's a lot of new
> warnings for little gain. We can't stop inheriting from Resource and can't
> deprecate dispose() anyway.
> 
> Also, to preserve existing behavior, any Colors created and returned by SWT
> should have a Device reference (i.e. use an old constructor).

I the past all Color instances have returned a Device instance from Resource#getDevice.

After this change that method might will throw SWTException(SWT.ERROR_GRAPHIC_DISPOSED).

Is that a problem?

It is probably rare for someone to call getDevice on a Color. But there might be some framework somewhere that does.

I don't know if this is a problem that is worth taking into consideration, I'm just raising the question.

One alternative is to give each Color a standards Device, like this:

https://git.eclipse.org/r/#/c/162994/5/bundles/org.eclipse.swt/Eclipse+SWT/gtk/org/eclipse/swt/graphics/Color.java@53
Comment 22 Eclipse Genie CLA 2020-05-21 17:38:04 EDT
New Gerrit change created: https://git.eclipse.org/r/163388
Comment 23 Eclipse Genie CLA 2020-05-21 17:46:30 EDT
New Gerrit change created: https://git.eclipse.org/r/163389
Comment 24 Dani Megert CLA 2020-05-25 11:02:18 EDT
Please fix for RC1.
Comment 25 Jonah Graham CLA 2020-05-25 14:40:20 EDT
(In reply to Dani Megert from comment #24)
> Please fix for RC1.

I will split most of the remaining work into Bug 563560 - e.g. the new API seems to require additional discussion/review.

The main thing left on this bug is N&N entry and making sure existing API documentation is correct. I'll provide a further comment with the gerrits that are still relevant and require review shortly.
Comment 26 Jonah Graham CLA 2020-05-25 14:49:43 EDT
Removed gerrits that are not relevant from See Also. They have been moved to Bug 563018.

The gerrit that still needs review & merge for 4.16 is https://git.eclipse.org/r/#/c/163204/ - Improve description of Color.dispose - which was created as a result of a comment in another review.

The N&N gerrit will be here soon.
Comment 27 Eclipse Genie CLA 2020-05-25 15:00:49 EDT
New Gerrit change created: https://git.eclipse.org/r/163555
Comment 30 Alexander Kurtakov CLA 2020-05-26 08:26:13 EDT
(In reply to Jonah Graham from comment #26)
> Removed gerrits that are not relevant from See Also. They have been moved to
> Bug 563018.

^ this points to the current bug. Do you mean some other bug?

> 
> The gerrit that still needs review & merge for 4.16 is
> https://git.eclipse.org/r/#/c/163204/ - Improve description of Color.dispose
> - which was created as a result of a comment in another review.
> 
> The N&N gerrit will be here soon.

Both merged.
Comment 31 Jonah Graham CLA 2020-05-26 08:51:34 EDT
(In reply to Alexander Kurtakov from comment #30)
> (In reply to Jonah Graham from comment #26)
> > Removed gerrits that are not relevant from See Also. They have been moved to
> > Bug 563018.
> 
> ^ this points to the current bug. Do you mean some other bug?

Yes. Bug 563560.

> 
> > 
> > The gerrit that still needs review & merge for 4.16 is
> > https://git.eclipse.org/r/#/c/163204/ - Improve description of Color.dispose
> > - which was created as a result of a comment in another review.
> > 
> > The N&N gerrit will be here soon.
> 
> Both merged.

Thank you. I think that means we are done with this bug and can continue in 4.17 timeframe in Bug 563560