cyclecollector.nim 431 B

123456789101112131415161718192021222324
  1. # Program to detect bug #1796 reliably
  2. type
  3. Node = ref object
  4. a, b: Node
  5. leaf: string
  6. proc createCycle(leaf: string): Node =
  7. new result
  8. result.a = result
  9. when defined(gcArc) or defined(gcOrc):
  10. result.leaf = leaf
  11. else:
  12. shallowCopy result.leaf, leaf
  13. proc main =
  14. for i in 0 .. 100_000:
  15. var leaf = "this is the leaf. it allocates"
  16. let x = createCycle(leaf)
  17. let y = createCycle(leaf)
  18. main()