The code below leaks memory and doesn't print "memory deallocated" (so the
object's destructor isn't called). If the `cycler` coroutine isn't created, no
leak occurs. Am I doing something wrong, or is there a memory manager bug at
play? Tried both `2.0.8` and `2.1.9` nim versions. Compiled with
Another piece of info: replacing `std/asyncdispatch` with `chronos` fixes the
problem in this case. But the problem returns with the following changes:
proc cycler(x: ref MyObj) {.async.} =
while true:
x.value[] += 1
echo x.value[]
await sleepAsync(200)
Update: after manually clearing dispatcher's `callbacks` and `timers` and
manually calling a GC the memory is properly freed, even when the `cycle`
coroutine is still pending. So the question is: why do I have to do this
manually? Shouldn't this be done automatically when the thread finishes?
T
I have a nim function that will be called from a C thread. I'm using mm:orc,
and the docs say the the heap is shared in this case. Is it possible to create
ref types and store them in nim-managed memory inside such a function? How does
such a function interact with heap and GC?
I have some imported C function that looks like `proc doStuff(..., callback:
proc(pointer) {.cdecl.}, ctx: pointer)`. It does stuff, and on completion calls
the callback with ctx. I know that the callback will be called from another
thread. I'd like to wait for completion in a coroutine. Right n
The following setup with `AsyncEvent` seems to work. Not sure how to clean up
the event properly, so used `close` and `unregister` (from the nim thread)
defensively. Improvements are welcome.
type Context = object
refCount: int
foreignRefCount: int
lock: Lock