www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Another bug in the GC

reply Bill Baxter <dnewsgroup billbaxter.com> writes:
This bug seems to be related to pointers in mixins not getting treated 
as pointers.
(filed as bug 892 -- just posting here to make sure it gets noticed)

------------------------
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");
}
------------------------------------

With DMD 1.003 this outputs:

SomeObject created
---Pre collect
SomeObject destroyed
---Post collect
Jan 27 2007
parent reply renoX <renosky free.fr> writes:
The joy of GCs.. :-(
I remember a bug in Sun's JVM: the GC wouldn't take into account static 
reference to object, freeing 'singleton' objects during the collection..
Took me some time to figure what was happening (especially since 
collection phase occur more or less randomly).

renoX
Jan 26 2007
parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
renoX wrote:
 The joy of GCs.. :-(
 I remember a bug in Sun's JVM: the GC wouldn't take into account static 
 reference to object, freeing 'singleton' objects during the collection..
 Took me some time to figure what was happening (especially since 
 collection phase occur more or less randomly).
 
 renoX
Did Sun not have an equivalent of std.gc.fullCollect to force a GC cycle? (sorry about my previous posts from the future -- forgot that I set my timezone to something bogus the other day.) --bb
Jan 26 2007
parent renoX <renosky free.fr> writes:
Bill Baxter a écrit :
 renoX wrote:
 The joy of GCs.. :-(
 I remember a bug in Sun's JVM: the GC wouldn't take into account 
 static reference to object, freeing 'singleton' objects during the 
 collection..
 Took me some time to figure what was happening (especially since 
 collection phase occur more or less randomly).

 renoX
Did Sun not have an equivalent of std.gc.fullCollect to force a GC cycle?
I think they have, but it's useful only when you have figured what's happening to reproduce it, at the begining there are just weird exceptions at random time, and I didn't suspect the GC for some time.. renoX
 
 (sorry about my previous posts from the future -- forgot that I set my 
 timezone to something bogus the other day.)
 
 --bb
Jan 27 2007