qlua / luainterface

Automatically exported from code.google.com/p/luainterface
0 stars 0 forks source link

Memory Leak! #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
ObjectTranslator objects,objectsBackMap will cause Memory Leak.

if we call a lua function in C#.
example:
  T={
     Test=function(dotNetObj)
       dotNetObj:Test();
     end,
  }
the arg dotNetObj will be hold by ObjectTranslator.objects and  
ObjectTranslator.objectsBackMap 

also the lua's gc will call collectObject method and remove some reference in 
ObjectTranslator.objects and  ObjectTranslator.objectsBackMap, but most of them 
will be hold until lua.Dispose() be called.

i think we can do like this:
  usually,some dotNetObj will be used in the live time of luastate.so,we can mark these dotNetObj. In lua class,we add a ManualGC() method to release reference in ObjectTranslator.objects and  ObjectTranslator.objectsBackMap. 

IT COULD BE WORK?

Original issue reported on code.google.com by isSin...@gmail.com on 17 Jul 2010 at 2:58

GoogleCodeExporter commented 9 years ago
ps:In lua class,we add a ManualGC() method to release reference which is not 
marked in ObjectTranslator.objects and  ObjectTranslator.objectsBackMap  

Original comment by isSin...@gmail.com on 17 Jul 2010 at 3:01

GoogleCodeExporter commented 9 years ago
i think the bug is in the callFunction method in lua object

as it pushes the values but never pops them off when done

Original comment by icewolfz...@gmail.com on 18 Jul 2010 at 6:16

GoogleCodeExporter commented 9 years ago
i added 
        public void GC()
        {
            LuaDLL.lua_gc(luaState, LuaGCOptions.LUA_GCCOLLECT, 0);
        }

to lua class, you can then do Lua.GC() and force garbarge collection.

now this wont get every thing as object could still be in use by lua or such 
but i added to the callMethod just ebfore returning and it cleans yup some 
objects, but could slow down possibly, best bet if you are concerned is call 
the GC method your self after all your code is executed and it should clean up 
memeory.

Original comment by icewolfz...@gmail.com on 22 Jul 2010 at 7:05

GoogleCodeExporter commented 9 years ago
We came across a similar issue recently, after some memory profiling I 
discovered LuaBase was keeping a reference to _Interpreter after Dispose had 
been called which seemed to be keeping some objects alive seemingly forever.

LuaBase is inherited from in quite a few places and I haven't done a lot of 
testing, see attached for a patch. 

If someone can review and verify it hasn't broken anything I'll commit it in.

Original comment by capre...@gmail.com on 13 Aug 2010 at 6:46

Attachments: