Using ltrace to debug a memory leak
jvns.ca
jvns.ca
pprof heap profiles make this kind of thing easy to debug. It draws a call graph using graphviz. Boxes are scaled according the total byte size, so if there's a large leak you can pull up the graph and the giant box all but says "you idiot, the problem is right here".
The type of .boxed() would probably help. I would expect a .boxed to return a Box<_> (e.g. Vec::into_boxed_slice(v) returns a Box<[_]>) which would get RAII-deallocated. So either .boxed() returns a raw pointer for some reason, or it properly returns a Box but leaks internally.
It's not a leak but this kind of thing is often detected as a positive slope in a process' RSS graph and it's common to refer to it as a "memory leak" because from this symptom it's indistinguishable from an actual leak.
Whether "I added one FramistanObject to the FramistanObjectLog for every single HTTPConnection" is a logic error or not depends on what the intended design was.
Also check out https://rachelbythebay.com/
Technically yes, but for allocations you need to run nightly and either alloc_system (disable jemalloc) or rebuild nightly with JEMALLOC_FLAGS='--enable-valgrind', otherwise valgrind misses jemalloc's allocations, which is more or less all of them: https://github.com/rust-lang/rust/issues/28224
And the second fix may or may not keep working as jemalloc 5 apparently removes valgrind support: https://github.com/jemalloc/jemalloc/issues/369
Thanks for the tip!
However, the only reason you'd have for using std::mem::forget would be because you're doing unsafe things elsewhere in the program (as discussed at http://doc.rust-lang.org/std/mem/fn.forget.html ), so you're correct that in practice there's almost always an `unsafe` block somewhere that's the culprit.