-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak under Arc/Orc on inline iterators with nested seq. #24402
Comments
Here's valgrind's output on above example when nim is passed
|
!nim c --gc:orc iterator myPairsInline*[T](twoDarray: seq[seq[T]]): (int, seq[T]) {.inline.} =
for indexValuePair in twoDarray.pairs:
yield indexValuePair
iterator myPairsClosure*[T](twoDarray: seq[seq[T]]): (int, seq[T]) {.closure.} =
for indexValuePair in twoDarray.pairs:
yield indexValuePair
template testTotalMem(iter: untyped): int =
proc innerTestTotalMem(): int {.gensym.} =
result = 0
# do the same operation 100 times, which should have similar mem footprint
# as doing it once.
for iterNum in 0..100:
result = max(result, getTotalMem()) # record current mem footprint
# initialize nested sequence
var my2dArray: seq[seq[int32]] = @[]
# fill with some data...
for i in 0'i32..10_000:
var z = @[i, i+1]
my2dArray.add z
# use that data somehow...
var otherContainer: seq[int32] = @[]
var count = 0'i32
for oneDindex, innerArray in my2dArray.iter:
for value in innerArray:
inc count
if oneDindex > 50 and value < 200:
otherContainer.add count
innerTestTotalMem()
proc main =
let closureMem = testTotalMem(myPairsClosure) #1052672
let inlineMem = testTotalMem(myPairsInline) #20328448
when defined(echoFootprint):
echo "Closure memory footprint: " & $closureMem
echo "Inline memory footprint: " & $inlineMem
# check that mem footprint is relatively similar b/t each method
doAssert (closureMem - inlineMem).abs < (closureMem div 10)
main() |
!nim c --gc:orc -d:useMalloc iterator myPairsInline*[T](twoDarray: seq[seq[T]]): (int, seq[T]) {.inline.} =
for indexValuePair in twoDarray.pairs:
yield indexValuePair
iterator myPairsClosure*[T](twoDarray: seq[seq[T]]): (int, seq[T]) {.closure.} =
for indexValuePair in twoDarray.pairs:
yield indexValuePair
template testTotalMem(iter: untyped): int =
proc innerTestTotalMem(): int {.gensym.} =
result = 0
# do the same operation 100 times, which should have similar mem footprint
# as doing it once.
for iterNum in 0..100:
result = max(result, getTotalMem()) # record current mem footprint
# initialize nested sequence
var my2dArray: seq[seq[int32]] = @[]
# fill with some data...
for i in 0'i32..10_000:
var z = @[i, i+1]
my2dArray.add z
# use that data somehow...
var otherContainer: seq[int32] = @[]
var count = 0'i32
for oneDindex, innerArray in my2dArray.iter:
for value in innerArray:
inc count
if oneDindex > 50 and value < 200:
otherContainer.add count
innerTestTotalMem()
proc main =
let closureMem = testTotalMem(myPairsClosure) #1052672
let inlineMem = testTotalMem(myPairsInline) #20328448
when defined(echoFootprint):
echo "Closure memory footprint: " & $closureMem
echo "Inline memory footprint: " & $inlineMem
# check that mem footprint is relatively similar b/t each method
doAssert (closureMem - inlineMem).abs < (closureMem div 10)
main() |
🐧 Linux bisect by @juancarlospaco (collaborator)devel 👎 FAILOutput
Filesize stable 👎 FAILOutput
Filesize 2.0.10 👎 FAILOutput
Filesize 2.0.0 👎 FAILOutput
Filesize 1.6.20 👎 FAILOutput
Filesize 1.4.8 👎 FAILOutput
Filesize 1.2.18 👎 FAILOutput
Filesize 1.0.10 👎 FAILOutput
Filesize Stats
🤖 Bug found in |
Description
On the arc, orc, and atomicArc mm's: Inline iterators that do not return a lent type leak memory when iterating upon nested sequences. Closures that do not return lent types and inlines that do return lent types do not leak.
Nim Version
Nim Compiler Version 2.2.0 [Linux: amd64]
Current Output
Expected Output
No response
Known Workarounds
No response
Additional Information
The regions gc/mm scheme is the only other gc that fails this example.
The text was updated successfully, but these errors were encountered: