Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

GC bug or feature?

Moderators: kris

Posted: 04/08/08 07:31:35 Modified: 04/09/08 09:17:48

Hi, I found out this:

struct A
{
  A* p1;
  A* p2;
}

A* a=new A;
//... do some work
a.p1=a.p1.p1;
//now the original a.p1 is wiped by the GC (maybe not immediately), although the pointer it contains is still in use

Is it a bug or feature?

Thanks, bobef

Author Message

Posted: 04/08/08 21:15:57

I am not sure that I am able to follow your program, but the pointer you claim is still in use - it seems that would be a dangling pointer? That is, not referenced by your program, thus it is cleanable by the GC.

Posted: 04/09/08 09:21:13

Yes, a.p1 is not in use anymore after a.p1=a.p1.p1, but for some reason a.p1.p1 gets wiped out too, and it is in use. If I do like this everything is fine:

A* a=new A;
//... do some work
auto t=a.p1;
a.p1=t.p1;

Posted: 04/09/08 09:22:33

I don't think the above sounds very good in (my) English. Sorry :)

Posted: 04/10/08 17:17:54

Hmm, if a.p1.p1 is cleaned after a.p1 = a.p1.p1, then there may be an issue. I'm not able to help you further right now though.

Posted: 04/10/08 20:03:47

This sounds like a code gen bug to me. Have you verified:

auto t = a.p1;
assert( a.p1.p1 is t.p1 );

I'm guessing that by saying "a.p1.p1" is still in use that the only living reference to it is expected to be in a.p1 after the assignment takes place?