From 083d4f47083755b80be8356f89cf25d8608cb661 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Wed, 5 Dec 2012 20:42:19 +0200 Subject: 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) --- tests/gc/refarrayleak.nim | 39 +++++++++++++++++++++++++++++++++++++++ tests/gc/stackrefleak.nim | 2 -- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/gc/refarrayleak.nim (limited to 'tests/gc') 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() + diff --git a/tests/gc/stackrefleak.nim b/tests/gc/stackrefleak.nim index 2c652d6bf..302ef3599 100644 --- a/tests/gc/stackrefleak.nim +++ b/tests/gc/stackrefleak.nim @@ -29,5 +29,3 @@ proc loop = loop() - - -- cgit 1.4.1-2-gfad0