   [C++/Lua][LuaBind] garbage collection problem
  I m currently working on a luabind implementation of some of my c++ classes in a 2d engine.i m experiencing some problems with my C++ management of object and lua garbage collectorfor instance, i ve got a list a drawable object of differents type (texts, sprites, gui elements)  in C++ i create object via the new operator and add object to a std::vector which contains all the elements and take care of drawing and updating object via polymorphismthe problem occurs when i m deleting objectfor(int i=0;i<s.size();i++) {if (s){ delete s;s = NULL;}}if objects where created in C++ , there is no problem, but if i created objects via lua, lua garbage collector is not able to know that objects has already been deleted by C++I can use something like boost shared pointers but i would prefer another solution.i found some infos about luabind ownership , but cant get it to work ( http://www.nabble.com/How-to-create-objects-in-Lua-and-transfer-ownership-to-C%2B%2B-to8444299.html )i use luabind 0.8.1here is a code sample from my luabind implementationclass_<VGL_Sprite,VGL_SpriteBase>("VGL_Sprite").def(constructor<>()).def("Draw",&VGL_Sprite::Draw).def("SetMask",&VGL_Sprite::SetMask).def("Set",&VGL_Sprite::Set).def("Collide",(bool( VGL_Sprite::*)(const Vector2 & ))&VGL_Sprite::Collide)the only fix i was able to do for now is to totally disable lua gargabe collection.   
  There isn't any need to disable the garbage collector. If you don't want Lua to collect some shared object you can always keep it around in a table explicitly for that purpose until your done with it. Once the C++ side is finished with it you can then callback into Lua to nil out that reference and if there are no more references in Lua, it will be destroyed within a short timer later.If however you want Lua to own the object and be responsible for destroying it, there is a metamethod called during the garbage collection of an object. You can overload that and callback into the C++ side notifying the C++ engine that it's safe to destroy that object outside of Lua.I believe there is a lua function that explicitly does the first method, so you don't have to create a table, it creates a reference of an object to prevent that object from being collected until such time a deference call is made on that object. You'll have to look at the docs.Good Luck!-ddn   