[Issue 6666] New: gc finalization/freeing is hierarchy agnostic

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 13 17:59:05 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6666

           Summary: gc finalization/freeing is hierarchy agnostic
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P3
         Component: druntime
        AssignedTo: nobody at puremagic.com
        ReportedBy: dawg at dawgfoto.de


--- Comment #0 from dawg at dawgfoto.de 2011-09-13 17:58:47 PDT ---
class A
{
    ~this() {}
    void cleanup() {}
}

class B
{
    this(A a) { this.a = a; }
    ~this() { a.cleanup(); }
    A a;
}

void main() {
    auto a = new A();
    auto b = new B(a);
    // allocating a at a lower address than b causes it to be finalized earlier
    assert(cast(void*)b.a < cast(void*)b);
}
---

Finalization is done in memory order and does not take
hierarchies into account.
When b.a is finalized before b it's vtable is set to null, hence
a segfault will happen when accessing the vtable.
Anyhow a is destroyed before b even though it is referenced by b.

It seems like we need to somehow sort the to be finalized memory while
scanning.
Any cheap ideas to do that are welcome.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list