D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9111 - Parent object getting GCed before the elements of child dynamic array
Summary: Parent object getting GCed before the elements of child dynamic array
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-03 00:51 UTC by Puneet Goel
Modified: 2012-12-03 02:43 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Puneet Goel 2012-12-03 00:51:58 UTC
The following code segfaults when compiled with current DMD github snapshot. It seems that array elements of "frop" are getting garbage collected after the parent class Foo's object is collected.

Works fine with dmd-2.059 and dmd-2.060.


class Frop {
  bar _v;
}
struct bar {
  static Foo _root;
  ~this() {
    _root.del();
  }
}
class Foo {
  int _x;
  Frop[] _frop;
  this() {
    bar._root = this;
    _frop = [new Frop()];
  }
  void del() {}
}


void main() {
  auto foo = new Foo ;
}