Memory leak with ARC and malloc when using references and casts

2021-08-07 Thread ynfle
The reason that it doesn't leak without `-d:useMalloc` is because nim holds the memory in case it needs to be reallocated to the leak may not be as easily detectable

Memory leak with ARC and malloc when using references and casts

2021-08-07 Thread planetis
There is also the .cursor pragma, maybe you can avoid the table altogether somehow?

Memory leak with ARC and malloc when using references and casts

2021-08-07 Thread tsojtsoj
For completeness I'll mention how I solved the issue (at least how I _believe_ I solved the issue). For that I will shortly describe what I actually wanted to achieve. I wanted to create a small entity component manager. For that I need a type `TypeVector`, that can do something like this:

Memory leak with ARC and malloc when using references and casts

2021-08-07 Thread guibar
My guess: In this expandarc output, `:tmpD_1` is a temporary variable introduced to hold the `new seq[Component]` call. It it then in effect cast _and copied into r, that increments the underlying reference counter, both ``r`` and ``:tmpD_1`` shares a reference to the same buffer but with differ

Memory leak with ARC and malloc when using references and casts

2021-08-06 Thread tsojtsoj
the expandarc looks the same when compiler with or without `-d:useMalloc`, and as the version without the malloc doesn't leak, I assumed that there can't be a missing destroyer. To be honest, I don't quite understand the output: --expandArc: test var r :tmpD

Memory leak with ARC and malloc when using references and casts

2021-08-06 Thread planetis
My point is to inspect the output of expandarc and try to find if a destructor call is missing.

Memory leak with ARC and malloc when using references and casts

2021-08-06 Thread Stefan_Salewski
> as the issue happens only with --gc:arc -d:useMalloc The point is that valgrind can see the leak only with --gc:arc -d:useMalloc. See my book:

Memory leak with ARC and malloc when using references and casts

2021-08-06 Thread tsojtsoj
`--expandarc:test`doesn't help here, I believe, as the issue happens only with `--gc:arc -d:useMalloc` but not with only `--gc:arc`.

Memory leak with ARC and malloc when using references and casts

2021-08-06 Thread planetis
Best way to identify the leak is --expandarc:test. Then open a new issue on GitHub.

Memory leak with ARC and malloc when using references and casts

2021-08-06 Thread tsojtsoj
I fixed the issues with the first example. This still has the same leak issue: type ComponentC = ref object c: int func newComponentC(): ComponentC = result = new ComponentC result[].c = 150 proc test() = var r: ref seq[int8]

Memory leak with ARC and malloc when using references and casts

2021-08-06 Thread tsojtsoj
I tried again with the latest nightly, and it still behaves the same.

Memory leak with ARC and malloc when using references and casts

2021-08-06 Thread Hlaaftana
I don't know about the leak, but shouldn't this code not work? `ref ComponentC` becomes `ref ref int`, no? I assume this is what you meant to write: type ComponentC = ref object c: int func newComponentC(): ComponentC = result = new ComponentC result[

Memory leak with ARC and malloc when using references and casts

2021-08-06 Thread planetis
Fixed in devel right?

Memory leak with ARC and malloc when using references and casts

2021-08-05 Thread tsojtsoj
The following example doesn't leak when compiled with `nim c --gc:arc main.nim && valgrind --leak-check=full ./main`, but it does leak 16 bytes when compiled with `nim c --gc:arc -d:useMalloc main.nim && valgrind --leak-check=full ./main` type ComponentC = ref object c: int