git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [EGIT PATCH 3/8] Dispose of allocated colors on finalize()

From
Shawn O. Pearce <spearce@spearce.org>
Date
Oct 1, 2008, 14:37 UTC
Message-ID
<20081001143718.GU21310@spearce.org>
In-Reply-To
<1222818823-22780-3-git-send-email-robin.rosenberg@dewire.com>
Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
> ---
Missing SBO.
Show 21 quoted lines
>  .../egit/ui/internal/history/SWTPlotRenderer.java  |   11 +++++++++++
>  1 files changed, 11 insertions(+), 0 deletions(-)
> 
> diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/SWTPlotRenderer.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/SWTPlotRenderer.java
> index 23ec255..a58b3bf 100644
> --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/SWTPlotRenderer.java
> +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/SWTPlotRenderer.java
> @@ -45,6 +45,17 @@ SWTPlotRenderer(final Display d) {
>  		sys_darkblue = d.getSystemColor(SWT.COLOR_DARK_BLUE);
>  	}
>  
> +	@Override
> +	protected void finalize() throws Throwable {
> +		sys_black.dispose();
> +		sys_blue.dispose();
> +		sys_gray.dispose();
> +		sys_darkblue.dispose();
> +		sys_yellow.dispose();
> +		sys_green.dispose();
> +		sys_white.dispose();
> +	}

I think this is wrong. Any color that we get from Display.getSystemColor() must not be disposed of by the application, its in use by the Display and/or other parts of the application.

>From the Javadocs:
  This color should not be free'd because it was allocated by the
  system, not the application.
I take that to mean that the color should not be disposed of.

Though reading the Gtk SWT sources it seems that the system color objects aren't pooled, each call to getSystemColor causes a new Color instace to be allocated. So it may be harmless on Gtk.

What was the rationale for disposing of these resources? Did you identify that this is a resource leak somewhere? Because I'd like to make sure I actually understand the SWT resource model better so I don't commit mistakes in the future.

-- 
Shawn.
Previous: Robin RosenbergNext: Robin Rosenberg
Message 11 of 13 in “Set table row height for the glog JTable”
  1. 1/8 Set table row height for the glog JTableRobin Rosenberg, Sep 30, 2008
  2. 2/8 Move AWTPlotRenderer to its own file.Robin Rosenberg, Sep 30, 2008
  3. 3/8 Dispose of allocated colors on finalize()Robin Rosenberg, Sep 30, 2008
  4. 4/8 Align commit text properly in jgit glogRobin Rosenberg, Sep 30, 2008
  5. Robin RosenbergOct 1, 2008
  6. Shawn O. PearceOct 1, 2008
  7. 0/3 jgit glog alignment fixesRobin Rosenberg, Oct 1, 2008
  8. 1/3 Set table row height for the glog JTableRobin Rosenberg, Oct 1, 2008
  9. 2/3 Move AWTPlotRenderer to its own file.Robin Rosenberg, Oct 1, 2008
  10. 3/3 Align commit text properly in jgit glogRobin Rosenberg, Oct 1, 2008
  11. Shawn O. PearceOct 1, 2008
  12. Robin RosenbergOct 1, 2008
  13. Shawn O. PearceOct 1, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.