Open PhilippMDoerner opened 4 weeks ago
Turns out you need to indeed call =destroy(getThreadDispatcher())
on the dispatcher and do so before you collect all cycles with GC_fullCollect()`. That solved it.
Turns out you need to indeed call =destroy(getThreadDispatcher()) on the dispatcher and do so before you collect all cycles with GC_fullCollect()`. That solved it.
feel free to turn this into a documentation page outlining multithreaded / orc + chronos use
Actually, pretty solid advice. I'm repurposing this issue for a PR towards that change
For the purposes of decent examples with async-event-loop in other threads and cleaning up after them: Are there easy ways to tell chronos "process your remaining async work" ? I didn't get around to asking that one yet I think
Heyho, still trying to write my multithreading library and ensuring correctness with address sanitizer. I've been running into memory leak issues of around 20KB with the way I have set up my code (meaning
asyncSpawn
on a Future at the start of a loop, and process the async-work that came from that at a later part in the loop whilewaitFor
-ing ThreadSignalPtr).I managed to condense it down into this minimal example, which I do not understand why that leaks:
There is nothing that should leak there. All futures that exist from
processAsync
should be resolved once during thesleep
call. You can see that in the console as well sinceStuff
will get printed there. So what is leaking?Command to compile:
nim r -f --debugger:native --cc:clang -d:useMalloc --passc:"-fsanitize=address -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" --passl:"-fsanitize=address -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" -d:release src/playground.nim
Address sanitizer stacktraces:
```txt 50823==ERROR: LeakSanitizer: detected memory leaks Direct leak of 256 byte(s) in 1 object(s) allocated from: #0 0x599e1c7426f1 in calloc (/home/isofruit/.cache/nim/playground_r/playground_CAED38D1B3F5F9549C0D683A5A5C9A6761A36907+0x1266f1) (BuildId: 45b58de06b1e762d7de2cf93447bf65a9b6087d7) #1 0x599e1c796063 in nimNewObj /home/isofruit/.choosenim/toolchains/nim-2.0.4/lib/system/arc.nim:81:343 #2 0x599e1c7be8eb in asyncengine::newDispatcher /home/isofruit/.nimble/pkgs2/chronos-4.0.2-5ed2d147ae4760a4ec6f01daf794df761b5229af/chronos/internal/asyncengine.nim:752:88 #3 0x599e1c7beebb in asyncengine::getThreadDispatcher /home/isofruit/.nimble/pkgs2/chronos-4.0.2-5ed2d147ae4760a4ec6f01daf794df761b5229af/chronos/internal/asyncengine.nim:1093:39 #4 0x599e1c7bfe4c in asyncengine::setTimer(timer::Moment, proc