C++で作ったクラスをLuaから扱う場合、binding-generatorを使うとGlueCodeの生成が自動化できて便利ですが、何も設定しないとLuaからインスタンス化したC++のオブジェクトが解放されません。
class Hoge {
public:
Hoge(){};
~Hoge(){ log("release"); };
};
local hoge = Hoge:new()
hoge = nil
collectgarbage("collect") -- releaseは表示されない
これは、cocos2dxで使われるほとんどのクラスが独自のReferenceCountでメモリ管理されており、シーンを切り替えたタイミングやretainしたものをreleaseしたタイミングでメモリが解放されるからだと思われます。
Luaからインスタンス化したクラスをLuaのGCのタイミングで解放するには、binding-generatorに渡す.iniファイルの最後の設定を変更します。
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = yes
コメントにも書かれている通り、script_control_cppをyesにします。これでLuaのGCでメモリが解放されます。
local hoge = Hoge:new()
hoge = nil
collectgarbage("collect") -- releaseが表示される