stackrefleak.nim 493 B

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. outputsub: "no leak: "
  3. """
  4. type
  5. Cyclic = object
  6. sibling: PCyclic
  7. data: array[0..200, char]
  8. PCyclic = ref Cyclic
  9. proc makePair: PCyclic =
  10. new(result)
  11. new(result.sibling)
  12. result.sibling.sibling = result
  13. proc loop =
  14. for i in 0..10000:
  15. var x = makePair()
  16. GC_fullCollect()
  17. x = nil
  18. GC_fullCollect()
  19. if getOccupiedMem() > 300_000:
  20. echo "still a leak! ", getOccupiedMem()
  21. quit(1)
  22. else:
  23. echo "no leak: ", getOccupiedMem()
  24. loop()