diff options
Diffstat (limited to 'tests/gc')
-rw-r--r-- | tests/gc/closureleak.nim | 4 | ||||
-rw-r--r-- | tests/gc/cyclecollector.nim | 21 | ||||
-rw-r--r-- | tests/gc/gcleak4.nim | 4 | ||||
-rw-r--r-- | tests/gc/gctest.nim | 3 | ||||
-rw-r--r-- | tests/gc/growobjcrash.nim | 29 |
5 files changed, 57 insertions, 4 deletions
diff --git a/tests/gc/closureleak.nim b/tests/gc/closureleak.nim index 38ee1250a..1c39f43d5 100644 --- a/tests/gc/closureleak.nim +++ b/tests/gc/closureleak.nim @@ -7,7 +7,7 @@ from strutils import join type TFoo * = object id: int - func: proc(){.closure.} + fn: proc(){.closure.} var foo_counter = 0 var alive_foos = newseq[int](0) @@ -26,7 +26,7 @@ for i in 0 .. <10: for i in 0 .. <10: let f = newFoo() - f.func = proc = + f.fn = proc = echo f.id GC_fullcollect() diff --git a/tests/gc/cyclecollector.nim b/tests/gc/cyclecollector.nim new file mode 100644 index 000000000..46fed6c45 --- /dev/null +++ b/tests/gc/cyclecollector.nim @@ -0,0 +1,21 @@ + +# Program to detect bug #1796 reliably + +type + Node = ref object + a, b: Node + leaf: string + +proc createCycle(leaf: string): Node = + new result + result.a = result + shallowCopy result.leaf, leaf + +proc main = + for i in 0 .. 100_000: + var leaf = "this is the leaf. it allocates" + let x = createCycle(leaf) + let y = createCycle(leaf) + echo "done ", getOccupiedMem() + +main() diff --git a/tests/gc/gcleak4.nim b/tests/gc/gcleak4.nim index 6f2b8a1fe..54e74ac7b 100644 --- a/tests/gc/gcleak4.nim +++ b/tests/gc/gcleak4.nim @@ -38,12 +38,14 @@ proc newPlus(a, b: ref TExpr): ref TPlusExpr = result.b = b result.op2 = $getOccupiedMem() +const Limit = when compileOption("gc", "markAndSweep"): 5*1024*1024 else: 500_000 + for i in 0..100_000: var s: array[0..11, ref TExpr] for j in 0..high(s): s[j] = newPlus(newPlus(newLit(j), newLit(2)), newLit(4)) if eval(s[j]) != j+6: quit "error: wrong result" - if getOccupiedMem() > 500_000: quit("still a leak!") + if getOccupiedMem() > Limit: quit("still a leak!") echo "no leak: ", getOccupiedMem() diff --git a/tests/gc/gctest.nim b/tests/gc/gctest.nim index 27134d7dd..2213a83ac 100644 --- a/tests/gc/gctest.nim +++ b/tests/gc/gctest.nim @@ -196,7 +196,8 @@ write(stdout, "starting main...\n") main() GC_fullCollect() +# the M&S GC fails with this call and it's unclear why. Definitely something +# we need to fix! GC_fullCollect() writeln(stdout, GC_getStatistics()) write(stdout, "finished\n") - diff --git a/tests/gc/growobjcrash.nim b/tests/gc/growobjcrash.nim new file mode 100644 index 000000000..a16468c7e --- /dev/null +++ b/tests/gc/growobjcrash.nim @@ -0,0 +1,29 @@ +discard """ + output: "works" +""" + +import cgi, strtabs + +proc handleRequest(query: string): StringTableRef = + iterator foo(): StringTableRef {.closure.} = + var params = {:}.newStringTable() + for key, val in cgi.decodeData(query): + params[key] = val + yield params + + let x = foo + result = x() + +const Limit = when compileOption("gc", "markAndSweep"): 5*1024*1024 else: 700_000 + +proc main = + var counter = 0 + for i in 0 .. 100_000: + for k, v in handleRequest("nick=Elina2&type=activate"): + inc counter + if counter mod 100 == 0: + if getOccupiedMem() > Limit: + quit "but now a leak" + +main() +echo "works" |