From eafd6ebf08be2015ad05af7920b9d125a5058510 Mon Sep 17 00:00:00 2001 From: Rohan Kuruvilla Date: Thu, 11 Oct 2012 18:05:25 -0700 Subject: [PATCH] Fixing restart of context to not leak memory --- scripting/javascript/bindings/ScriptingCore.cpp | 6 ++++++ scripting/javascript/bindings/cocos2d_specifics.hpp | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/scripting/javascript/bindings/ScriptingCore.cpp b/scripting/javascript/bindings/ScriptingCore.cpp index ff9e094ccc..4004074eb5 100644 --- a/scripting/javascript/bindings/ScriptingCore.cpp +++ b/scripting/javascript/bindings/ScriptingCore.cpp @@ -372,6 +372,12 @@ void ScriptingCore::removeAllRoots(JSContext *cx) { js_proxy_t *current, *tmp; HASH_ITER(hh, _js_native_global_ht, current, tmp) { JS_RemoveObjectRoot(cx, ¤t->obj); + HASH_DEL(_js_native_global_ht, current); + free(current); + } + HASH_ITER(hh, _native_js_global_ht, current, tmp) { + HASH_DEL(_native_js_global_ht, current); + free(current); } HASH_CLEAR(hh, _js_native_global_ht); HASH_CLEAR(hh, _native_js_global_ht); diff --git a/scripting/javascript/bindings/cocos2d_specifics.hpp b/scripting/javascript/bindings/cocos2d_specifics.hpp index b77fb840ce..03c34ce042 100644 --- a/scripting/javascript/bindings/cocos2d_specifics.hpp +++ b/scripting/javascript/bindings/cocos2d_specifics.hpp @@ -12,8 +12,7 @@ template inline js_type_class_t *js_get_type_from_native(T* native_obj) { js_type_class_t *typeProxy; - const char *n = typeid(*native_obj).name(); - long typeId = getHashCodeByString(n); + long typeId = getHashCodeByString(typeid(*native_obj).name()); HASH_FIND_INT(_js_global_type_ht, &typeId, typeProxy); if (!typeProxy) { TypeInfo *typeInfo = dynamic_cast(native_obj);