vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.51k stars 2.15k forks source link

memory leak when closure #21019

Open joysahimar opened 3 months ago

joysahimar commented 3 months ago

Describe the bug

Hi, i have a function that has a closure. However, when I run it with a loop, I see the memory is very high. ~700mb on my linux.

Reproduction Steps

Code :

fn foo(i int) fn () int {
    return fn [i]() int {
        return i
    }
}

fn main() {
    for i in 0 .. 100000000 {
        println(foo(i)())
    }
}

Run :

v run main.v

look at app monitor.

Expected Behavior

<1mb memroy usage.

Current Behavior

~700mb memory usage

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.4 7ffd917

Environment details (OS name and version, etc.)

V full version: V 0.4.4 790ea2f.7ffd917 OS: linux, Pop!_OS 20.04 LTS Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-4030U CPU @ 1.90GHz

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

williamd67 commented 3 weeks ago

This may have been introduced by this commit: 26d051475ac3a33031eec1936e813dc3f088d2fb