Skip to content

Commit

Permalink
fix for --gc:orc
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Feb 24, 2020
1 parent 9fac41f commit a44da13
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions tests/gc/gcleak2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ proc makeObj(): TTestObj =
result.s = @[1,2,3]

const collectAlways = defined(gcMarkAndSweep) or defined(boehmgc)
const isDeterministic = collectAlways or defined(gcArc) or defined(gcOrc)

var memMax = 0 # peak

Expand All @@ -29,7 +30,7 @@ else:
var memMin = -1 # right after a peak
var numCollections = 0

let numIter = when collectAlways: 1_000 else: 1_000_000
let numIter = when isDeterministic: 1_000 else: 1_000_000
## full collection is expensive, and the memory doesn't change after
## each iteration so there's no point in a large `numIter` (this was taking
## 350s for `nim c -r -d:release --gc:boehm` + `nim c -r --gc:boehm`, 50%
Expand All @@ -41,7 +42,7 @@ proc inProc() =
var obj: TTestObj
obj = makeObj()
let mem = getOccupiedMem()
when collectAlways:
when isDeterministic:
if i <= 2:
memMax = mem
doAssert memMax <= 50_000 # adjust as needed
Expand Down Expand Up @@ -69,10 +70,12 @@ proc inProc() =
memPrevious = mem

inProc()
when collectAlways:
let msg = getOccupiedMem()
let mem = getOccupiedMem()
var msg = "no leak: "
when isDeterministic:
msg.add $(mem, memMax)
echo msg
else:
when not defined(gcOrc): # getOccupiedMem() is always 0, wich seems like a bug
doAssert numCollections > 1000 # 3999 on local OSX; leaving some slack
let msg = $(getOccupiedMem(), memMin, memMax, numCollections, numIter)
echo "no leak: ", msg
msg.add $(mem, memMin, memMax, numCollections, numIter)
echo msg
doAssert numCollections > 1000 # 3999 on local OSX; leaving some slack

0 comments on commit a44da13

Please sign in to comment.