calling the GC when destrouying nodes

This commit is contained in:
Gabriel mermelstein 2025-03-13 13:15:27 +02:00
parent d5f18cf455
commit 1090b6018f
2 changed files with 17 additions and 0 deletions

View File

@ -183,6 +183,17 @@ proc waku_destroy(
initializeLibrary()
checkLibwakuParams(ctx, callback, userData)
let retCode = handleRequest(
ctx,
RequestType.LIFECYCLE,
NodeLifecycleRequest.createShared(NodeLifecycleMsgType.DESTROY_NODE, nil, nil),
callback,
userData,
)
if retCode != RET_OK:
return RET_ERR
waku_thread.destroyWakuThread(ctx).isOkOr:
let msg = "libwaku error: " & $error
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
@ -191,6 +202,8 @@ proc waku_destroy(
## always need to invoke the callback although we don't retrieve value to the caller
callback(RET_OK, nil, 0, userData)
echo "----------- calling GC_fullCollect in host thread"
GC_fullCollect()
return RET_OK
proc waku_version(

View File

@ -14,6 +14,7 @@ type NodeLifecycleMsgType* = enum
CREATE_NODE
START_NODE
STOP_NODE
DESTROY_NODE
type NodeLifecycleRequest* = object
operation: NodeLifecycleMsgType
@ -99,5 +100,8 @@ proc process*(
except Exception:
error "STOP_NODE failed", error = getCurrentExceptionMsg()
return err("exception stopping node: " & getCurrentExceptionMsg())
of DESTROY_NODE:
echo "----------- calling GC_fullCollect in waku thread"
GC_fullCollect()
return ok("")