Hello everyone, I am new in Nim and I am trying to develop a software with it. I was experiencing some estrange (to me) behavior in my code: `arc` and `orc` garbage collectors lead to different results. I'm not sure if this is because I am doing something incorrect, as I'm not familiar with reference objects or pointers. Maybe the underlying logic of my program is wrong.
Y defined several related `Object` types: `System`, `Polyhedra`, `Surface`, `Point`, and a few more (but no `ref Object` was defined). * `System` contains sequences of `Polyhedra`, `Surface` and `Point` **objects**. * `Polyhedra` contains sequences of `Surface` and `Point` **ref objects** (that refer to those in the sequences of `System`). * `Surface` contains sequences of `Point` **ref objects** (that refer to those in the sequences of `System`). The flow goes like this: 1. Create `Point` _objects_ 2. Add Point _objects_ to a System object with something like: `mySystem.points.add(myPointN)` 3. Create `Surface` _objects_ and add refs to the points belonging to `mySystem.points` using `cast[ref Point](addr mySystem.points[indexOfThePoint])` 4. Add Surface _objects_ to a System object: `mySystem.surfaces.add(mySurfaceN)` and modify the `triangles` (`seq[array[3,int]`) attribute of the surfaces now in `mySystem.surfaces`. 5. Create _just one_ `Polyhedra` _objects_ and add it to `mySystem.polyedra` seq. 6. Add to `mySystem.polyhedra[0]` ref to Surface objects in `mySystem.surfaces`. The problem arises when performing step 6. The `triangles` attribute of `mySystem.surfaces[0]` changes after adding the second reference to a surface object to `mySystem.polyhedra[0].surfaces`. For example, I set: `mySystem.surfaces[0].triangles` to `@[[1,2,3][4,5,6]]` by performing two `add` operations. After doing `mySystem.polyhedra[0].surfaces.add(cast[ref Surface](addr mySystem.surfaces[0]))` it is still `@[[1,2,3][4,5,6]]`. But if I immediately add another ref to a surface: `mySystem.polyhedra[0].surfaces.add(cast[ref Surface](addr mySystem.surfaces[1]))` , then `mySystem.surfaces[0].triangles` turns to be: @[[3, 4, 5], [6, 0, 2]] if using **orc** , using **arc** lets `mySystem.surfaces[0].triangles` untouched, that is `@[[1,2,3][4,5,6]]`. I expect the latter behavior because adding to a sequence a ref to a surface should not modify the attributes of another surface. I though that I may be a issue with bad initialization of variables, until I found that using `-mm:arc` solved it. I realize that **arc** gives the "correct" results after hours of trying to make it work. In some tests, I get a correct result when I removed some unrelated (and unused attribute of _Surface_). **Questions:** * Does this sound like a bug in ORC? Or should I just not use ORC for these kinds of things? Or is my workflow incorrect? (I just learned about pointers from Nim books and tutorials) Thank you for your help!