Re: how to create an array of scoped objects ?

2018-07-03 Thread Flaze07 via Digitalmars-d-learn
On Tuesday, 3 July 2018 at 15:06:28 UTC, Mike Parker wrote: .. That said, the GC in D runs when main exits anyway, so the destructor in your example will be called. That's why I warned earlier about it being nondeterministic. For example, if you have a Texture instance that depends on the

Re: how to create an array of scoped objects ?

2018-07-03 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 3 July 2018 at 14:42:58 UTC, Flaze07 wrote: On Tuesday, 3 July 2018 at 14:32:01 UTC, Mike Parker wrote: Resources allocated for the process will be released on exit. I see...but it is dependant on the OS right ? because I have seen other stuff relating to malloc as well, there

Re: how to create an array of scoped objects ?

2018-07-03 Thread Flaze07 via Digitalmars-d-learn
On Tuesday, 3 July 2018 at 14:32:01 UTC, Mike Parker wrote: Resources allocated for the process will be released on exit. I see...but it is dependant on the OS right ? because I have seen other stuff relating to malloc as well, there are some out there that said that there is no need to

Re: how to create an array of scoped objects ?

2018-07-03 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 3 July 2018 at 10:56:26 UTC, Flaze07 wrote: hmm, I assume you know about DSFML, so... i.e void main( string args[] ) { auto win = new RenderWindow( VideoMode( 400, 400 ), "resource leak ?" ); win.close(); } //in this context, is there any memory leak ? because I saw

Re: how to create an array of scoped objects ?

2018-07-03 Thread Flaze07 via Digitalmars-d-learn
On Tuesday, 3 July 2018 at 10:00:00 UTC, Mike Parker wrote: The only way you're going to be leaking resources is if the app is long running and the resource objects are never collected. I'd be more concerned about the nondeterministic nature of the destructor calls, particularly what happens

Re: how to create an array of scoped objects ?

2018-07-03 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 3 July 2018 at 07:29:12 UTC, Flaze07 wrote: class RenderWindow { private sfRenderWindow* _window; public { this() { _window = sfRenderWindow_create(/*parameters*/); } //couple of other functions ~this() {

Re: how to create an array of scoped objects ?

2018-07-03 Thread Flaze07 via Digitalmars-d-learn
On Tuesday, 3 July 2018 at 07:03:43 UTC, vit wrote: On Tuesday, 3 July 2018 at 02:13:21 UTC, Flaze07 wrote: e.g A is a class that emits output during destruction { auto a = scoped!A(); } how do I contain it in a container, in the Array struct ? { auto a = scoped!A(); Array!(

Re: how to create an array of scoped objects ?

2018-07-03 Thread vit via Digitalmars-d-learn
On Tuesday, 3 July 2018 at 02:13:21 UTC, Flaze07 wrote: e.g A is a class that emits output during destruction { auto a = scoped!A(); } how do I contain it in a container, in the Array struct ? { auto a = scoped!A(); Array!( typeof( a ) ) arr; foreach( i ; 0..3 ) {

how to create an array of scoped objects ?

2018-07-02 Thread Flaze07 via Digitalmars-d-learn
e.g A is a class that emits output during destruction { auto a = scoped!A(); } how do I contain it in a container, in the Array struct ? { auto a = scoped!A(); Array!( typeof( a ) ) arr; foreach( i ; 0..3 ) { arr.insertBack( scoped!A ); } } is that how you do it ?