On Monday, 21 March 2016 at 07:55:39 UTC, thedeemon wrote:
On Sunday, 20 March 2016 at 07:49:17 UTC, stunaep wrote:
The gc throws invalid memory errors if I use Arrays from
std.container.
Those arrays are for RAII-style deterministic memory release,
they shouldn't be freely mixed with GC-allocated things. What
happens here is while initializing Array sees it got some GC-ed
value type (strings), so it tells GC to look after those
strings. When your program ends runtime does a GC cycle, finds
your Test object, calls its destructor that calls Array
destructor that tries to tell GC not to look at its data
anymore. But during a GC cycle it's currently illegal to call
such GC methods, so it throws an error.
Moral of this story: try not to store "managed" (collected by
GC) types in Array and/or try not to have Arrays inside
"managed" objects. If Test was a struct instead of a class, it
would work fine.
So what am I do to? Any other language can do such a thing so
trivially... I also run into the same problem with
emsi_containers TreeMap. It is imperative that I can store data
such as
public class Example1 {
private File file;
public this(File f) {
this.file = f;
}
}
or
public class Example2 {
private int one;
private int two;
public this(int one, int two) {
this.one = one;
this.two = two;
}
}
in a tree map and list of some sort. Neither of the above work
whether they are classes or structs and it's starting to become
quite bothersome...