From 7576a538229f7d8ea7b8f89da062141dfcaefa12 Mon Sep 17 00:00:00 2001 From: cary <39078800+caryliu1999@users.noreply.github.com> Date: Fri, 2 Aug 2019 10:21:48 +0800 Subject: [PATCH] Fixed memory leak caused by HtmlCanvasElement not being released. (#1786) * Fixed memory leak caused by HtmlCanvasElement not being released. * modify unroot * add comment --- .../scripting/js-bindings/manual/jsb_cocos2dx_manual.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/native/cocos/scripting/js-bindings/manual/jsb_cocos2dx_manual.cpp b/native/cocos/scripting/js-bindings/manual/jsb_cocos2dx_manual.cpp index f245dea197..40f7c74572 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_cocos2dx_manual.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_cocos2dx_manual.cpp @@ -444,6 +444,12 @@ static bool js_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback(se::State se::ScriptEngine::getInstance()->clearException(); } }; + // Add an unroot to avoid the root of the copy constructor caused by the internal reference of Lambda. + if (jsThis.isObject()) + { + jsThis.toObject()->unroot(); + } + jsFunc.toObject()->unroot(); arg0 = lambda; } else