Thread overview | |||||
---|---|---|---|---|---|
|
April 21, 2008 scope keyword in 'parameter' context | ||||
---|---|---|---|---|
| ||||
I have this construct, but would like the new Image to be collected after it is used in the Texture constructor. texture = new Texture(new Image("data/models/cp2/a1.jpg")); I cannot say this, but would like to: texture = new Texture(scope new Image("data/models/cp2/a1.jpg")); Is there any workaround, other than: scope Image image = new Image("data/models/cp2/a1.jpg"); texture = new Texture(image); Presumably I could write some sort of mixin, which I haven't yet used at all in D. This may seem trivial, but it can be a pain where I want to do the same thing over, and know that I don't want to keep the Image object, and infact in some cases I *must* make sure it is collected before the end of main, as the library calls it uses become unavailable, as the library is unloaded at the end of main scope. |
April 22, 2008 Re: scope keyword in 'parameter' context | ||||
---|---|---|---|---|
| ||||
Posted in reply to Spacen Jasset | Spacen Jasset wrote:
> I have this construct, but would like the new Image to be collected after it is used in the Texture constructor.
>
> texture = new Texture(new Image("data/models/cp2/a1.jpg"));
>
> I cannot say this, but would like to:
>
> texture = new Texture(scope new Image("data/models/cp2/a1.jpg"));
>
> Is there any workaround, other than:
>
> scope Image image = new Image("data/models/cp2/a1.jpg");
> texture = new Texture(image);
>
> Presumably I could write some sort of mixin, which I haven't yet used at all in D.
>
>
> This may seem trivial, but it can be a pain where I want to do the same thing over, and know that I don't want to keep the Image object, and infact in some cases I *must* make sure it is collected before the end of main, as the library calls it uses become unavailable, as the library is unloaded at the end of main scope.
How about deleting it at the end of the image constructor?
|
April 22, 2008 Re: scope keyword in 'parameter' context | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | Robert Fraser wrote:
> Spacen Jasset wrote:
>> I have this construct, but would like the new Image to be collected after it is used in the Texture constructor.
>>
>> texture = new Texture(new Image("data/models/cp2/a1.jpg"));
>>
>> I cannot say this, but would like to:
>>
>> texture = new Texture(scope new Image("data/models/cp2/a1.jpg"));
>>
>> Is there any workaround, other than:
>>
>> scope Image image = new Image("data/models/cp2/a1.jpg");
>> texture = new Texture(image);
>>
>> Presumably I could write some sort of mixin, which I haven't yet used at all in D.
>>
>>
>> This may seem trivial, but it can be a pain where I want to do the same thing over, and know that I don't want to keep the Image object, and infact in some cases I *must* make sure it is collected before the end of main, as the library calls it uses become unavailable, as the library is unloaded at the end of main scope.
>
> How about deleting it at the end of the image constructor?
Yes true, but I don't always want it deleted.
|
Copyright © 1999-2021 by the D Language Foundation