Extremely funny behavior .. could be a bug?
seany via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Sep 12 06:35:35 PDT 2014
consider the following :
in file a.d
module a;
class class_a
{
struct RESULT{
string[] raw;
void* res;
}
RESULT r;
void dothing()
{
r = new RESULT;
string aa = "string";
r.raw ~= aa;
r.res = cast(void*) aa;
}
}
in file b.d
import a; // import path is okey
class class_b;
{
void doThings(class_a * ptr_a)
{
class_a A = &ptr_a;
writeln(A.r.raw[0]); // prints aa;
writeln(A.r.res); // fails :
core.exception.OutOfMemoryError@(0)
// but if i do comment the line :
// writeln(A.r.raw[0]); out, then
works
}
}
in file c.d
import a;
import b;
void main() {
clsa = new class_a;
clsb = new class_b;
clsa.dothing();
clsa.doThings( & clsa);
}
I can not find a reason why accessing A.r.raw will erase (invoke
the garbage collector) to remove A.r.res. Please help.
More information about the Digitalmars-d-learn
mailing list