Memory leak in foreach

aliak something at something.com
Wed Feb 20 10:50:50 UTC 2019


On Wednesday, 20 February 2019 at 09:31:30 UTC, Andrea Fontana 
wrote:
> This subtle bug[1] and its memory leak are still here because 
> my pull request[2] had no success.
>
> It worths noting that since each() in std.algorithm uses a 
> foreach+ref to iterate  structs[3], this memory leak probably 
> is silently affecting not only me :)
>
> I hope someone could fix this.
>
> [1] https://issues.dlang.org/show_bug.cgi?id=11934
> [2] https://github.com/dlang/dmd/pull/8437
> [3] 
> https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d#L983

Does that patch ignore the ref when you specify it in a foreach 
loop?

If it does, then that sounds like it should be a compiler error 
and not ignored. A compiler should not change the meaning of my 
code silently just to make compilation work. We have javascript 
for that no?

Or did I misunderstand the patch?


More information about the Digitalmars-d mailing list