Hello, is there any tools out there for debugging memory leaks and trace dependencies in Nim with GC. For python I use objgraph+graphviz to visualize object dependencies with is extremely useful.
My platform of choice is GNU/Linux. I know/use Valgrind for C projects, but for a nim with GC it is not very useful.
As far as i know Instrumental app is somewhat like valgrind, ie for low level memory allocations. I am actually trying to detect references cycles, and reference inside global variables keeping some objects alive. As such I believe the tool must have knowledge of the Garbage Collector used.
For an example of such tool for python see: objgraph
I was looking for an already existing tool, but that's actually a good idea. Unfortunately I have only vague idea a GC actually works, so I don't think I could modify one to suit my needs. At least without some serious help and a lot of time.
Maybe an idea for a new project.
I have actually used the typeinfo module in the past to access parent type info in inherited types, but I remember it was a bit of a hack.
Ok, so i found a way to view object dependencies in a graph. All the tools already existed :)
First use the compile flag -gc:v2 to switch away from the default GC then at some point call GC_dumpHeap(outfile) to dump the heap content to the file.
In the $NIM_FOLDER/tools/ use the script called heapdump2dot to convert from raw data to dot format. Then use the dot program to output the graph (svg, png or pdf)
heapdump2dot heapdump.txt heapdump.dot | dot -Tsvg -o heapdump.svg
This will create an objects graph from the heap dump. As it is, it is not very useful as only addresses are exported but we should be able to modify the heap dump to export more information (at the very least the type of the objects).What the ...? Incredible that you found out these things on your own. I was about to write something along the lines. There is also the totally misnamed heapdump2sql tool that gives you a REPL to query the object graph. I found the dot graphs to be overwhelming and useless.
Now please help us to get v2 into production quality. :D
Well, I was combing through lib/system/gc2.nim and found a reference to GC_dumpHeap. From there it wasn't that difficult :)
However I couldn't find a reference to heapdump2sql anywhere in the code. Could you give me more details, it seems very useful. At the very least more than a giant graph. (The last one I extracted was 3500x32000 pixels)
I would be happy to help, especially if we can finally solve this issue. Although v2 does not seems to crash as often.