892 – Another bug in the new GC - pointers in mixins

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 892 - Another bug in the new GC - pointers in mixins
Summary: Another bug in the new GC - pointers in mixins
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks:
Reported: 2007年01月26日 14:20 UTC by Bill Baxter
Modified: 2014年02月16日 15:26 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Bill Baxter 2007年01月26日 14:20:33 UTC
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");
}
Comment 1 Bill Baxter 2007年01月26日 15:33:11 UTC
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);
}
Comment 2 Bill Baxter 2007年01月27日 01:17:49 UTC
Gone in 1.004.


AltStyle によって変換されたページ (->オリジナル) /