Skip to content

Instantly share code, notes, and snippets.

@pb-cdunn
Created March 22, 2017 15:36
Show Gist options
  • Save pb-cdunn/9ac52d96d1791cbb2412e76865748a13 to your computer and use it in GitHub Desktop.
Save pb-cdunn/9ac52d96d1791cbb2412e76865748a13 to your computer and use it in GitHub Desktop.
Nimlang free memory rising
# vim: sw=2 ts=2 sts=2 tw=80 et:
from strutils import repeat, `%`
proc log*(msgs: varargs[string]) =
for s in msgs:
write(stderr, s)
write(stderr, '\L')
return
proc scan_i() =
const N = 31
var list: seq[string]
newSeq(list, N)
for i in 0..<N:
var base = char(i + 64)
var n = 1 shl i
log("n=", $n)
var ls: ref string
new(ls)
ls[] = repeat(base, n)
list.add(ls[])
log("tot=$1 occ=$2, free=$3 b4" % [$getTotalMem(), $getOccupiedMem(), $getFreeMem()])
GC_fullCollect()
log("tot=$1 occ=$2, free=$3 now" % [$getTotalMem(), $getOccupiedMem(), $getFreeMem()])
proc scan() =
for j in 0..25:
scan_i()
when isMainModule:
scan()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment