www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - scope keyword in 'parameter' context

reply Spacen Jasset <spacen yahoo.co.uk> writes:
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.
Apr 21 2008
parent reply Robert Fraser <fraserofthenight gmail.com> writes:
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?
Apr 21 2008
parent Spacen Jasset <spacenjasset yahoo.co.uk> writes:
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.
Apr 22 2008