Forcing a memory leak in Nim

2020-10-18 Thread shirleyquirk
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

Forcing a memory leak in Nim

2020-10-17 Thread leorize
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

Forcing a memory leak in Nim

2020-10-17 Thread leorize
> 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

Forcing a memory leak in Nim

2020-10-17 Thread Yardanico
The thing is that even when manually allocating stuff you use Nim's TLSF allocator unless you switch to -d:useMalloc

Forcing a memory leak in Nim

2020-10-17 Thread o24
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

Forcing a memory leak in Nim

2020-10-17 Thread Yardanico
useMalloc also works with ORC or refc for that matter

Forcing a memory leak in Nim

2020-10-17 Thread shirleyquirk
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

Forcing a memory leak in Nim

2020-10-17 Thread Stefan_Salewski
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.

Forcing a memory leak in Nim

2020-10-17 Thread shirleyquirk
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.

Forcing a memory leak in Nim

2020-10-17 Thread juancarlospaco
Just `var mem = create int` should do.

Forcing a memory leak in Nim

2020-10-17 Thread o24
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