Memory leaks when using if var := some_map[type] {...}
#19454
Labels
Bug
This tag is applied to issues which reports bugs.
Option Type
Bugs/feature requests, that are related to `?Type`.
Result Type
Bugs/feature requests, that are related to `!Type`.
Unit: cgen
Bugs/feature requests, that are related to the default C generating backend.
Unit: Compiler
Bugs/feature requests, that are related to the V compiler in general.
Unit: Memory Management
Bugs/feature requests, that are related to the memory management of the compiler.
Describe the bug
Initial message and more info in this Discord thread: https://discord.com/channels/592103645835821068/592114487759470596/1156587254429536389
Running the following code with:
v -gc none run ./bug.v
, produces a memory leak:Running this example with
v -gc none run ./bug.v
while observing memory usage, you'll notice that memory grows slowly.Compiling with
v -trace-calls -gc none run ./bug.v > /tmp/bug_trace.txt 2>&1
and examining the output after a few seconds reveals calls like like this:My guess is that the error / option / result leaks memory behind the scenes?
Reproduction Steps
bug.v
:Run with
v -gc none run ./bug.v
and observe how memory grows steadily.Expected Behavior
No memory leak
Current Behavior
Memory leaks
Possible Solution
In this case @spytheman noted on Discord that changing the function
is_key_down(keycode KeyCode) bool
to the following code stops the leak:This is not a general solution, though
Additional Information/Context
Initial message and more info in this Discord thread: https://discord.com/channels/592103645835821068/592114487759470596/1156587254429536389
V version
V 0.4.1 12ee3fa
Environment details (OS name and version, etc.)
EndeavourOS (Arch based / rolling) distro
Note
You can vote for this issue using the 👍 reaction. More votes increase the issue's priority
for developers.
Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.
The text was updated successfully, but these errors were encountered: