tarc2.nim 500 B

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. output: '''leak: false'''
  3. cmd: '''nim c --gc:orc $file'''
  4. """
  5. type
  6. T = ref object
  7. s: seq[T]
  8. data: string
  9. proc create(): T = T(s: @[], data: "abc")
  10. proc addX(x: T; data: string) =
  11. x.data = data
  12. {.push sinkInference: off.}
  13. proc addX(x: T; child: T) =
  14. x.s.add child
  15. {.pop.}
  16. proc main(rootName: string) =
  17. var root = create()
  18. root.data = rootName
  19. root.addX root
  20. let mem = getOccupiedMem()
  21. main("yeah")
  22. GC_fullCollect()
  23. echo "leak: ", getOccupiedMem() - mem > 0