Bug in destructors
Andrej Mitrovic
andrej.mitrovich at gmail.com
Mon Sep 13 11:31:17 PDT 2010
This was discussed here:
http://www.digitalmars.com/d/archives/digitalmars/D/TDPL_Manual_invocation_of_destructor_114875.html
On Mon, Sep 13, 2010 at 8:19 PM, Rob Grainger
<rob_grainger2000 at yahoo.co.uk> wrote:
> The following example is based on one from The D Programming Language. I'd expect the last assertion in
> the unittest to succeed, it fails.
>
> class Buffer {
> private void* data;
>
> // Constructor
> this () {
> data = malloc(1024);
> }
> // Destructor
> ~this() {
> free(data);
> data = null;
> }
> }
> unittest {
> auto b = new Buffer;
> auto b1 = b;
> clear(b); // Get rid of b's extra state
> assert (b1.data is null); // Should be ok, fails
> }
>
More information about the Digitalmars-d
mailing list