You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Emmanuel Lécharny <el...@gmail.com> on 2015/04/20 18:42:31 UTC

[Studio] Color disposal

Hi Stefan,

just to be sure, there are many places we create Color() objects, but we
never dispose them. The API documentation says :

"You must dispose the color when it is no longer required."

I was thiunking about moving the color declaration to the
CommonUIConstants class, and free them in the CommonUIPlugin class, tjis
way :

in CommonUIConstants :   
    public static final Color BLACK_COLOR = new Color( null, BLACK );

and in CommonUIPlugin :

    public void stop( BundleContext context ) throws Exception
    {
        plugin = null;
       
        // Dispose the colors
        CommonUIConstants.BLACK_COLOR.dispose();
        CommonUIConstants.WHITE_COLOR.dispose();
        ...

Do you think this is correct ?

For specific colors, I think creating them in the Plugin where they are
used, and disposing them there too is the right way.

wdyt ?


Re: [Studio] Color disposal

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 20/04/15 19:23, Stefan Seelmann a écrit :
> On 04/20/2015 06:42 PM, Emmanuel Lécharny wrote:
>> Hi Stefan,
>>
>> just to be sure, there are many places we create Color() objects, but we
>> never dispose them. The API documentation says :
>>
>> "You must dispose the color when it is no longer required."
> In fact that is true for all classes in org.eclipse.swt.graphics.*
>
>> I was thiunking about moving the color declaration to the
>> CommonUIConstants class, and free them in the CommonUIPlugin class, tjis
>> way :
>>
>> in CommonUIConstants :   
>>     public static final Color BLACK_COLOR = new Color( null, BLACK );
>>
>> and in CommonUIPlugin :
>>
>>     public void stop( BundleContext context ) throws Exception
>>     {
>>         plugin = null;
>>        
>>         // Dispose the colors
>>         CommonUIConstants.BLACK_COLOR.dispose();
>>         CommonUIConstants.WHITE_COLOR.dispose();
>>         ...
>>
>> Do you think this is correct ?
> Hm, it doesn't look correct. The creation is done in static initalizer
> but the dispose in bundle stop method. What if the bundle is started
> again, then the static initialization isn't done. (or does OSGi does it?)

Rigth, right ! And we have a 'start' method just for that. Will work
around the idea.
>
>> For specific colors, I think creating them in the Plugin where they are
>> used, and disposing them there too is the right way.
>>
>> wdyt ?
>>
> Yes, that sounds good.
>
> I'm sure we lack lot of resources. I think we need to tackle them but
> first I'd like to get a release out...
Sure ! I was just asking because I was faced with the issue, and wanted
to know what to do about it.

Bottom line : I'll create a JIRA.

Thanks Stefan !


Re: [Studio] Color disposal

Posted by Stefan Seelmann <ma...@stefan-seelmann.de>.
On 04/20/2015 06:42 PM, Emmanuel Lécharny wrote:
> Hi Stefan,
> 
> just to be sure, there are many places we create Color() objects, but we
> never dispose them. The API documentation says :
> 
> "You must dispose the color when it is no longer required."

In fact that is true for all classes in org.eclipse.swt.graphics.*

> I was thiunking about moving the color declaration to the
> CommonUIConstants class, and free them in the CommonUIPlugin class, tjis
> way :
> 
> in CommonUIConstants :   
>     public static final Color BLACK_COLOR = new Color( null, BLACK );
> 
> and in CommonUIPlugin :
> 
>     public void stop( BundleContext context ) throws Exception
>     {
>         plugin = null;
>        
>         // Dispose the colors
>         CommonUIConstants.BLACK_COLOR.dispose();
>         CommonUIConstants.WHITE_COLOR.dispose();
>         ...
> 
> Do you think this is correct ?

Hm, it doesn't look correct. The creation is done in static initalizer
but the dispose in bundle stop method. What if the bundle is started
again, then the static initialization isn't done. (or does OSGi does it?)

> For specific colors, I think creating them in the Plugin where they are
> used, and disposing them there too is the right way.
> 
> wdyt ?
> 

Yes, that sounds good.

I'm sure we lack lot of resources. I think we need to tackle them but
first I'd like to get a release out...

Kind Regards,
Stefan