I incorporated lua into my small game engine using toLua++. Everything was fine until I noticed memory leak on certain situations. When I call a function from C++ side using lua, if function returns a value instead of a reference, those objects are never deleted by GC.
For example, in the following code, such leak is occuring:
bulletPos = Bullets.ref:getPosition() --getPosition returns a Vector3 value, not a pointer
Well, quoting the reference manual:
p1 = Point:new(0.0,1.0)
p2 = ColorPoint:new(1.5,2.2,0,0,255)
print(Point.n) -- would print 2
print(Point:get_n()) -- would also print 2
p3 = p1:add(p2) -- add method definition: Point add (Point& other);
local p4 = ColorPoint() print(p3.x,p3.y) -- would print 1.5 and 3.2
print(p2.red,p2.green,p2.blue) -- would print 0, 0, and 255
p1:delete() -- call destructor
p2:delete() -- call destructor
It says "the point p3 will be garbage-collected by tolua automatically; we cannot delete it."
But in my case they are not collected. Am I missing something? Any help is appreciated.