gcleak3.nim 504 B

12345678910111213141516171819202122232425262728293031
  1. discard """
  2. outputsub: "no leak: "
  3. """
  4. when defined(GC_setMaxPause):
  5. GC_setMaxPause 2_000
  6. type
  7. TSomething = object
  8. s: string
  9. s1: string
  10. var s: seq[TSomething] = @[]
  11. for i in 0..1024:
  12. var obj: TSomething
  13. obj.s = "blah"
  14. obj.s1 = "asd"
  15. s.add(obj)
  16. proc limit*[t](a: var seq[t]) =
  17. var loop = s.len() - 512
  18. for i in 0..loop:
  19. #echo i
  20. #GC_fullCollect()
  21. if getOccupiedMem() > 3000_000: quit("still a leak!")
  22. s.delete(i)
  23. s.limit()
  24. echo "no leak: ", getOccupiedMem()