Skip to content
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

fixes #24402; Memory leak under Arc/Orc on inline iterators with nested seq #24419

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

ringabout
Copy link
Member

@ringabout ringabout commented Nov 8, 2024

fixes #24402

iterator myPairsInline*[T](twoDarray: seq[seq[T]]): (int, seq[T]) {.inline.} =
  for indexValuePair in twoDarray.pairs:
    yield indexValuePair

proc innerTestTotalMem() =
  var my2dArray: seq[seq[int32]] = @[]

  # fill with some data...
  for i in 0'i32..100:
    var z = @[i, i+1]
    my2dArray.add z

  for oneDindex, innerArray in myPairsInline(my2dArray):
    discard

innerTestTotalMem()

In for oneDindex, innerArray in myPairsInline(my2dArray), oneDindex and innerArray becomes cursors because they satisfy the criterion of isSimpleIteratorVar. On the one hand, it is not correct to have them point to the temporary generated by tuple unpacking, which left the memory of the temporary uncleaned up. On the other hand, we don't need to generate a temporary for a symbol node when unpacking the tuple.

@Araq Araq merged commit 21420d8 into devel Nov 12, 2024
21 checks passed
@Araq Araq deleted the pr_24402 branch November 12, 2024 21:57
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 21420d8

Hint: mm: orc; opt: speed; options: -d:release
177497 lines; 8.663s; 653.258MiB peakmem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory leak under Arc/Orc on inline iterators with nested seq.
2 participants