refarrayleak.nim 612 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. outputsub: "no leak: "
  3. """
  4. type
  5. TNode = object
  6. data: array[0..300, char]
  7. PNode = ref TNode
  8. TNodeArray = array[0..10, PNode]
  9. TArrayHolder = object
  10. sons: TNodeArray
  11. proc nullify(a: var TNodeArray) =
  12. for i in 0..high(a):
  13. a[i] = nil
  14. proc newArrayHolder: ref TArrayHolder =
  15. new result
  16. for i in 0..high(result.sons):
  17. new result.sons[i]
  18. nullify result.sons
  19. proc loop =
  20. for i in 0..10000:
  21. discard newArrayHolder()
  22. if getOccupiedMem() > 300_000:
  23. echo "still a leak! ", getOccupiedMem()
  24. quit 1
  25. else:
  26. echo "no leak: ", getOccupiedMem()
  27. loop()