Thread overview
[Issue 892] New: Another bug in the new GC - pointers in mixins
Jan 26, 2007
d-bugmail
Jan 26, 2007
d-bugmail
Jan 27, 2007
d-bugmail
January 26, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=892

           Summary: Another bug in the new GC - pointers in mixins
           Product: D
           Version: 1.001
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: wbaxter@gmail.com


This is actually with DMD version 1.003 (and I suspect 1.001, and 1.002).

This program destroys the object from the mixin even though it is still very much referenced by live objects in the program.

------
import std.stdio;
static import std.gc;

class SomeObject
{
    this() { writefln("SomeObject created"); }
    ~this() { writefln("SomeObject destroyed"); }
}

template Mix()
{
    void init() {
        ptr = new SomeObject;
    }
    SomeObject ptr;
}

class Container
{
    this() { init(); }
    mixin Mix;
}


void main()
{
    auto x = new Container;

    writefln("---Pre collect");

    std.gc.fullCollect();

    writefln("---Post collect");
}


-- 

January 26, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=892





------- Comment #1 from wbaxter@gmail.com  2007-01-26 15:33 -------
OK, the compiler was being a bit too smart apparently, realizing that x would no longer be used.  That makes the test appear to fail all the way back to DMD 0.176.  So I should have put writeflns in at the end to make sure the data had a reason to stick around.

Upon doing that, the example works in DMD 1.0 and fails in 1.001--1.003 (I went ahead and tried them all).

Here's the modified test:

-----------------
import std.stdio;
static import std.gc;

class SomeObject
{
    this() { writefln("SomeObject created"); }
    ~this() { writefln("SomeObject destroyed"); }
}

template Mix()
{
    void init() {
        ptr = new SomeObject;
    }
    SomeObject ptr;
}

class Container
{
    this() { init(); }
    mixin Mix;

    int v = 10;
}


void main()
{
    auto x = new Container;

    writefln("---Pre collect");

    std.gc.fullCollect();
    writefln("---Post collect");

    writefln(x.v);
    writefln(x.ptr);
}


-- 

January 27, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=892


wbaxter@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from wbaxter@gmail.com  2007-01-27 01:17 -------
Gone in 1.004.


--