gcleak2.nim 898 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. outputsub: "no leak: "
  3. retries: 2
  4. """
  5. when defined(GC_setMaxPause):
  6. GC_setMaxPause 2_000
  7. type
  8. TTestObj = object of RootObj
  9. x: string
  10. s: seq[int]
  11. proc makeObj(): TTestObj =
  12. result.x = "Hello"
  13. result.s = @[1,2,3]
  14. const numIter =
  15. when defined(boehmgc):
  16. # super slow because GC_fullcollect() at each iteration; especially
  17. # on OSX 10.15 where it takes ~170s
  18. # `getOccupiedMem` should be constant after each iteration for i >= 3
  19. 1_000
  20. elif defined(gcMarkAndSweep):
  21. # likewise, somewhat slow, 1_000_000 would run for 8s
  22. # and same remark as above
  23. 100_000
  24. else: 1_000_000
  25. proc inProc() =
  26. for i in 1 .. numIter:
  27. when defined(gcMarkAndSweep) or defined(boehmgc):
  28. GC_fullcollect()
  29. var obj: TTestObj
  30. obj = makeObj()
  31. if getOccupiedMem() > 300_000: quit("still a leak!")
  32. inProc()
  33. echo "no leak: ", getOccupiedMem()