fixes a closure iterator memory leaks, progress on #15076
This commit is contained in:
parent
4c43915b59
commit
318f0992ea
2 changed files with 37 additions and 1 deletions
|
|
@ -787,7 +787,7 @@ proc p(n: PNode; c: var Con; s: var Scope; mode: ProcessMode): PNode =
|
||||||
if ri.kind == nkEmpty and c.inLoop > 0:
|
if ri.kind == nkEmpty and c.inLoop > 0:
|
||||||
ri = genDefaultCall(v.typ, c, v.info)
|
ri = genDefaultCall(v.typ, c, v.info)
|
||||||
if ri.kind != nkEmpty:
|
if ri.kind != nkEmpty:
|
||||||
result.add moveOrCopy(v, ri, c, s, isDecl = true)
|
result.add moveOrCopy(v, ri, c, s, isDecl = false)
|
||||||
else: # keep the var but transform 'ri':
|
else: # keep the var but transform 'ri':
|
||||||
var v = copyNode(n)
|
var v = copyNode(n)
|
||||||
var itCopy = copyNode(it)
|
var itCopy = copyNode(it)
|
||||||
|
|
|
||||||
36
tests/arc/tclosureiter.nim
Normal file
36
tests/arc/tclosureiter.nim
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
discard """
|
||||||
|
cmd: '''nim c -d:nimAllocStats --gc:arc $file'''
|
||||||
|
output: '''(allocCount: 102, deallocCount: 102)'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
FutureBase = ref object
|
||||||
|
someData: string
|
||||||
|
|
||||||
|
const
|
||||||
|
# Just to occupy some RAM
|
||||||
|
BigData = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||||
|
|
||||||
|
iterator mainIter(): FutureBase {.closure.} =
|
||||||
|
for x in 0 .. 100:
|
||||||
|
var internalTmpFuture = FutureBase(someData: BigData)
|
||||||
|
yield internalTmpFuture
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
var nameIterVar = mainIter
|
||||||
|
var next = nameIterVar()
|
||||||
|
while not isNil(next):
|
||||||
|
next = nameIterVar()
|
||||||
|
if not isNil(next):
|
||||||
|
doAssert next.someData.len == 97
|
||||||
|
# GC_unref(next)
|
||||||
|
# If you uncomment the GC_ref above,
|
||||||
|
# the program basically uses no memory after the run.
|
||||||
|
# but crashes with refc, which might indicate
|
||||||
|
# that arc/orc simply never frees the result of "next"?
|
||||||
|
if finished(nameIterVar):
|
||||||
|
break
|
||||||
|
|
||||||
|
main()
|
||||||
|
GC_fullCollect()
|
||||||
|
echo getAllocStats()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue