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 #22672; Destructor not called for result when exception is thrown #22742

Closed
wants to merge 2 commits into from

Conversation

ringabout
Copy link
Member

@ringabout ringabout commented Sep 22, 2023

fixes #22672

Given a piece of code in a try statement:

let s = initMyObj("Hello world")

Before it was translated into (exits before the assignment)

var s
let tmp = initMyObj("Hello world")
if raised: goto end
s = tmp
end: 
destroy s

Now it exits after the assignment.

var s
let tmp = initMyObj("Hello world")
s = tmp
if raised: goto end
end:
destroy s

Tested locally

The first example

bin/nim c -d:useMalloc -r

==5698== LEAK SUMMARY:
==5698==    definitely lost: 0 bytes in 0 blocks
==5698==    indirectly lost: 0 bytes in 0 blocks
==5698==      possibly lost: 0 bytes in 0 blocks

the second and the third examples

Both of them keep a constant memory consumption (208)

[GC] total memory: 528384
[GC] occupied memory: 208

[GC] total memory: 528384
[GC] occupied memory: 208

@ringabout ringabout marked this pull request as draft September 22, 2023 13:27
@ringabout
Copy link
Member Author

It seems that I need to find a way to properly destroy the tmp when raised. Work on it...

@ringabout ringabout closed this Feb 2, 2024
@ringabout ringabout deleted the ringabout-patch-5 branch February 2, 2024 12:14
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.

Destructor not called for result when exception is thrown
1 participant