according to the docs, useMalloc >only works with gc:none and with
--newruntime. which is a bit out of date, perhaps, but doublechecking the
source we have, in mmdisp.nim:
elif (defined(nogc) or defined(gcDestructors)) and defined(useMalloc):
include system / mm / malloc
It turns out that `valgrind` can only function if it could replaces libc's
`malloc` calls (see this
[FAQ](https://www.valgrind.org/docs/manual/faq.html#faq.hiddenbug)). The page
explicitly said that static linking and/or custom memory allocators are not
supported by valgrind. This should answer
> I am stil curious, however, why it does not leak with --gc:refc -d:useMalloc.
> Can you explain why this is?
Only `--gc:arc` and `--gc:orc` supports `-d:useMalloc`.
> Does Nim use its TLSF allocation even when the memory is a `ptr`?
Yes. If you're wondering, TSLF is just a memory allocator (l
The thing is that even when manually allocating stuff you use Nim's TLSF
allocator unless you switch to -d:useMalloc
Thanks, all. I'll go through these one by one.
> Just `var mem = create int` should do. `--gc:none` memory is never freed.
Using this program:
var mem = create int
mem = nil
Run
and compiling with `nim compile --gc:none leak.nim`, I still do **not** get a
memory
useMalloc also works with ORC or refc for that matter
I think useMalloc is necessary for valgrind to detect the leak, otherwise it is
hidden by Nims TLSF allocation, and useMalloc is only compatible with gcNone or
gcArc
First you may try to put the Nim code into a main proc, then it will become
closer to the C program. And maybe compile with -d:useMalloc and maybe also
with --gc:arc.
the fact that this doesn't compile with gc:none and -d:useMalloc is a
regression you could submit as an issue on github.
you can, however use gc:arc and -d:useMalloc, which then leaks as expected.
Just `var mem = create int` should do.
I am trying to force Nim to leak memory to better understand the memory model.
>From my understanding, the following two programs are identical.
#include
int main() {
int *x = malloc(sizeof(int));
x = 0;
}
Run
var mem: ptr int = c
11 matches
Mail list logo