Re: Question about Object.destroy

2015-09-20 Thread Lambert Duijst via Digitalmars-d-learn
On Sunday, 20 September 2015 at 18:50:44 UTC, Adam D. Ruppe wrote: On Sunday, 20 September 2015 at 18:41:18 UTC, anonymous wrote: But that doesn't change either. I think Adam is mistaken here. huh, I just checked the source... and you are right, it doesn't set classes to null itself, but

Re: Question about Object.destroy

2015-09-20 Thread ponce via Digitalmars-d-learn
On Sunday, 20 September 2015 at 17:43:01 UTC, Lambert Duijst wrote: Is it because: - The GC did decide to run and cleanup memory straight after the call to s.destroy() - An object being in an invalid state means the program segfaults when the object is used ? - Another reason.. All

Re: Question about Object.destroy

2015-09-20 Thread anonymous via Digitalmars-d-learn
On Sunday 20 September 2015 20:34, Lambert Duijst wrote: > On Sunday, 20 September 2015 at 18:21:52 UTC, Adam D. Ruppe wrote: [...] >> So after calling destroy(s), s is null, so it segfaults when >> you try to use it. [...] > Also when I print the address of s it gives me some hex number, > but

Re: Question about Object.destroy

2015-09-20 Thread Lambert Duijst via Digitalmars-d-learn
On Sunday, 20 September 2015 at 18:21:52 UTC, Adam D. Ruppe wrote: Very simple: destroy(s) (or s.destroy but i prefer destroy(s)) will set the reference it is passed to null because you aren't supposed to use it anymore. So after calling destroy(s), s is null, so it segfaults when you try to

Re: Question about Object.destroy

2015-09-20 Thread Adam D. Ruppe via Digitalmars-d-learn
Very simple: destroy(s) (or s.destroy but i prefer destroy(s)) will set the reference it is passed to null because you aren't supposed to use it anymore. So after calling destroy(s), s is null, so it segfaults when you try to use it.

Re: Question about Object.destroy

2015-09-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 20 September 2015 at 18:34:37 UTC, Lambert Duijst wrote: Oh that surprises me a bit, because I read in the list of deprecated features that delete is deprecated and that the right thing to do is to use destroy instead. Right. One of the benefits of destroy is that it nulls the

Re: Question about Object.destroy

2015-09-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 20 September 2015 at 18:41:18 UTC, anonymous wrote: But that doesn't change either. I think Adam is mistaken here. huh, I just checked the source... and you are right, it doesn't set classes to null itself, but does null out the vtable inside. *ppv = null; // zero vptr

Re: Question about Object.destroy

2015-09-20 Thread Lambert Duijst via Digitalmars-d-learn
On Sunday, 20 September 2015 at 18:39:57 UTC, Adam D. Ruppe wrote: On Sunday, 20 September 2015 at 18:34:37 UTC, Lambert Duijst wrote: Oh that surprises me a bit, because I read in the list of deprecated features that delete is deprecated and that the right thing to do is to use destroy

Re: Question about Object.destroy

2015-09-20 Thread Lambert Duijst via Digitalmars-d-learn
Thank you, this clarified a lot.

Question about Object.destroy

2015-09-20 Thread Lambert Duijst via Digitalmars-d-learn
Hi all, I have a question about the following piece of code that I wrote to experiment with explicit deletion of objects. I am interested in this because, even though D has a garbage collection, sometimes an object holds a non-memory resource, such as a file handle. In these cases explicit

Re: Question about Object.destroy

2015-09-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 20 September 2015 at 18:52:17 UTC, Lambert Duijst wrote: Just want to know if D protects against dangling pointers or is this just something you should never do. The answer is both: it tries to protect you but you still shouldn't do it. If we are not supposed to use