added 2 GC leak test cases
This commit is contained in:
parent
338683a198
commit
ad53e0b022
2 changed files with 75 additions and 0 deletions
42
tests/gc/cycleleak.nim
Normal file
42
tests/gc/cycleleak.nim
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
discard """
|
||||||
|
outputsub: "no leak: "
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
Module = object
|
||||||
|
nodes*: seq[PNode]
|
||||||
|
|
||||||
|
PModule = ref Module
|
||||||
|
|
||||||
|
Node = object
|
||||||
|
owner*: PModule
|
||||||
|
data*: array[0..200, char] # some fat to drain memory faster
|
||||||
|
|
||||||
|
PNode = ref Node
|
||||||
|
|
||||||
|
proc newNode(owner: PModule): PNode =
|
||||||
|
new(result)
|
||||||
|
result.owner = owner
|
||||||
|
|
||||||
|
proc compileModule: PModule =
|
||||||
|
new(result)
|
||||||
|
result.nodes = @[]
|
||||||
|
for i in 0..100:
|
||||||
|
result.nodes.add newNode(result)
|
||||||
|
|
||||||
|
var gModuleCache: PModule
|
||||||
|
|
||||||
|
proc loop =
|
||||||
|
for i in 0..10000:
|
||||||
|
gModuleCache = compileModule()
|
||||||
|
gModuleCache = nil
|
||||||
|
GC_fullCollect()
|
||||||
|
|
||||||
|
if getOccupiedMem() > 300_000:
|
||||||
|
echo "still a leak! ", getOccupiedMem()
|
||||||
|
quit(1)
|
||||||
|
else:
|
||||||
|
echo "no leak: ", getOccupiedMem()
|
||||||
|
|
||||||
|
loop()
|
||||||
|
|
||||||
33
tests/gc/stackrefleak.nim
Normal file
33
tests/gc/stackrefleak.nim
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
discard """
|
||||||
|
outputsub: "no leak: "
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
Cyclic = object
|
||||||
|
sibling: PCyclic
|
||||||
|
data: array[0..200, char]
|
||||||
|
|
||||||
|
PCyclic = ref Cyclic
|
||||||
|
|
||||||
|
proc makePair: PCyclic =
|
||||||
|
new(result)
|
||||||
|
new(result.sibling)
|
||||||
|
result.sibling.sibling = result
|
||||||
|
|
||||||
|
proc loop =
|
||||||
|
for i in 0..10000:
|
||||||
|
var x = makePair()
|
||||||
|
GC_fullCollect()
|
||||||
|
x = nil
|
||||||
|
GC_fullCollect()
|
||||||
|
|
||||||
|
if getOccupiedMem() > 300_000:
|
||||||
|
echo "still a leak! ", getOccupiedMem()
|
||||||
|
quit(1)
|
||||||
|
else:
|
||||||
|
echo "no leak: ", getOccupiedMem()
|
||||||
|
|
||||||
|
loop()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue