From 1090b6018ffc837465d6c26fb5dca21080e47e70 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Thu, 13 Mar 2025 13:15:27 +0200 Subject: [PATCH] calling the GC when destrouying nodes --- library/libwaku.nim | 13 +++++++++++++ .../requests/node_lifecycle_request.nim | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/library/libwaku.nim b/library/libwaku.nim index 258ac27b2..ed28d1178 100644 --- a/library/libwaku.nim +++ b/library/libwaku.nim @@ -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( diff --git a/library/waku_thread/inter_thread_communication/requests/node_lifecycle_request.nim b/library/waku_thread/inter_thread_communication/requests/node_lifecycle_request.nim index 9bd0017ab..7105c1c7d 100644 --- a/library/waku_thread/inter_thread_communication/requests/node_lifecycle_request.nim +++ b/library/waku_thread/inter_thread_communication/requests/node_lifecycle_request.nim @@ -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("")