tlists.nim 882 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. output: '''Success'''
  3. """
  4. # bug #3793
  5. import os
  6. import math
  7. import lists
  8. import strutils
  9. proc mkleak() =
  10. # allocate 1 MB via linked lists
  11. let numberOfLists = 100
  12. for i in countUp(1, numberOfLists):
  13. var leakList = initDoublyLinkedList[string]()
  14. let numberOfLeaks = 5000
  15. for j in countUp(1, numberOfLeaks):
  16. leakList.append(newString(200))
  17. proc mkManyLeaks() =
  18. for i in 0..0:
  19. when false: echo getOccupiedMem()
  20. mkleak()
  21. when false: echo getOccupiedMem()
  22. # Force a full collection. This should free all of the
  23. # lists and bring the memory usage down to a few MB's.
  24. GC_fullCollect()
  25. when false: echo getOccupiedMem()
  26. if getOccupiedMem() > 8 * 200 * 5000 * 2:
  27. echo GC_getStatistics()
  28. quit "leaking"
  29. echo "Success"
  30. mkManyLeaks()