cyclecollector.nim 460 B

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