diff options
author | Zahary Karadjov <zahary@gmail.com> | 2012-12-05 20:42:19 +0200 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2012-12-20 15:51:21 +0200 |
commit | 083d4f47083755b80be8356f89cf25d8608cb661 (patch) | |
tree | cbd78421ed5c04fe31f70f22cd5dd1e03e306aea /tests/gc/refarrayleak.nim | |
parent | d0edb1826b2c49413b6b7b1b9b351a632bd323f9 (diff) | |
download | Nim-083d4f47083755b80be8356f89cf25d8608cb661.tar.gz |
fixes the recently discovered GC memory leaks
This revision is intended as comparison point between the old and the new GC The used GC can be switched in mmdisp and various statistics will be gathered during execution (these will be removed/disabled in later revisions)
Diffstat (limited to 'tests/gc/refarrayleak.nim')
-rw-r--r-- | tests/gc/refarrayleak.nim | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/gc/refarrayleak.nim b/tests/gc/refarrayleak.nim new file mode 100644 index 000000000..12c9145f8 --- /dev/null +++ b/tests/gc/refarrayleak.nim @@ -0,0 +1,39 @@ +discard """ + outputsub: "no leak: " +""" + +type + TNode = object + data: array[0..300, char] + + PNode = ref TNode + + TNodeArray = array[0..10, PNode] + + TArrayHolder = object + sons: TNodeArray + +proc nullify(a: var TNodeArray) = + for i in 0..high(a): + a[i] = nil + +proc newArrayHolder: ref TArrayHolder = + new result + + for i in 0..high(result.sons): + new result.sons[i] + + nullify result.sons + +proc loop = + for i in 0..10000: + discard newArrayHolder() + + if getOccupiedMem() > 300_000: + echo "still a leak! ", getOccupiedMem() + quit 1 + else: + echo "no leak: ", getOccupiedMem() + +loop() + |