Re: class destruction

2015-09-09 Thread ponce via Digitalmars-d-learn
a C Handle which is destroyed as soon as the struct gets destroyed (more or less like a unique pointer) and I stick this struct into a class (because I strongly need polymorphism)? Then you have to make sure the class destruction happens and not rely on the GC. Can I be sure that the Handle

Re: class destruction

2015-09-09 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 07:19:58 UTC, Q wrote: Besides, we live in 2015 and that is not C where I have to clean my code manually, so this option would be ridiculous :D The difference is that in C you need to manage POD memory too. Manual management of non-POD resources is a problem

class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
Hi. I'm playing around with D for a while and I would like to switch. But here is one thing, I need an answer for. In the Docs is mentioned that it is not sure that the DTor of a class is called. But what if I have struct, which holds a C Handle which is destroyed as soon as the struct gets

Re: class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
But if others use my code they must think about finalizing the classes? That is very awkward. I'll take a look at Rust and otherwise I will stick with C++. Thanks for you answer. :)

Re: class destruction

2015-09-09 Thread ponce via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 14:36:24 UTC, Q wrote: But if others use my code they must think about finalizing the classes? That is very awkward. classes, yes but structs, no. I'll take a look at Rust and otherwise I will stick with C++. Thanks for you answer. :) Well, resource

Re: class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:32:58 UTC, Adam D. Ruppe wrote: On Wednesday, 9 September 2015 at 15:24:57 UTC, Q wrote: I thought that is not guaranteed, according to the docs? It is possible that the GC will never actually run, but you can force it to if you need it to by calling

Re: class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 14:57:26 UTC, Adam D. Ruppe wrote: On Wednesday, 9 September 2015 at 07:19:58 UTC, Q wrote: Can I be sure that the Handle is destroyed as soon as the class is destroyed? It will do that automatically. Like the others said, you won't be sure when the class is

Re: class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
And sorry if that sounds rude, I'm just in a hurry. I just think D is not mature enough for serious stuff. :) That is of course only my personal opinion.

Re: class destruction

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:24:57 UTC, Q wrote: I thought that is not guaranteed, according to the docs? It is possible that the GC will never actually run, but you can force it to if you need it to by calling GC.collect at any time.

Re: class destruction

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:37:50 UTC, Q wrote: Yes, but according to the specs it is not guaranteed that the GC calls the DTor if the Object is collected. Where? This page says pretty plainly: http://dlang.org/class.html#destructors "The garbage collector calls the destructor

Re: class destruction

2015-09-09 Thread Meta via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:37:50 UTC, Q wrote: Yes, but according to the specs it is not guaranteed that the GC calls the DTor if the Object is collected. Note that I believe this is the same as in Java (though not C#, interestingly enough). In Java an object's destructor is not

Re: class destruction

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 07:19:58 UTC, Q wrote: Can I be sure that the Handle is destroyed as soon as the class is destroyed? It will do that automatically. Like the others said, you won't be sure when the class is destroyed unless you have the user code take ownership of it. (This

Re: class destruction

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:10:33 UTC, Q wrote: But since D has a GC and (per default) force to heap allocate a class. So IMO the GC should also destroy it, everything else is just awkward. Well, it *does* by default. If that's what you want, just do it the plain way with simple

Re: class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:19:04 UTC, Adam D. Ruppe wrote: On Wednesday, 9 September 2015 at 15:10:33 UTC, Q wrote: But since D has a GC and (per default) force to heap allocate a class. So IMO the GC should also destroy it, everything else is just awkward. Well, it *does* by