Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Lua question... — Gideros Forum

Lua question...

GregBUGGregBUG Guru
edited February 2012 in General questions
sorry guys i need a little help...
i'm not an expert in Lua coding but
why in this code
function TestInit()
	TestList = {}
end
 
function TestCreate(name, xPos, yPos, Direction, parentGroup)
	local TTest = { 
		name = name, 
		xPos = xPos, 
		yPos = yPos, 
		Direction = Direction,
		anotherList = {},
		parentGroup = nil 
	}
	TestList[name] = TTest
	TestList[name].name = name
	TestList[name].xPos = xPos
	TestList[name].yPos = yPos
	TestList[name].Direction = Direction
	TestList[name].parentGroup = parentGroup
	return TestList[name]
end
 
function TestDone()
	for key,value in pairs(TestList) do 
		value.anotherList = nil
		TestList[key] = nil
	end
	TestList = nil
end
 
-- test
print ("memory used:"..collectgarbage("count"))
TestInit()
TestCreate("ciao", 10,10,33,nil)
TestCreate("ciao3", 10,10,33,nil)
TestCreate("ci22", 220, 410, 56, nil)
TestCreate("ci232", 220, 410, 56, nil)
TestDone()
print ("memory used:"..collectgarbage("count"))
there is a memory leak?
in testDone() function i nil all tables and other ref. !

TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
www.tntengine.com

Comments

  • atilimatilim Maintainer
    Hi,

    In fact, there is no memory leak. Just call collectgarbage() before printing collectgarbage("count")
    --...............
     
    -- test
    collectgarbage()
    print ("memory used:"..collectgarbage("count"))
    TestInit()
    TestCreate("ciao", 10,10,33,nil)
    TestCreate("ciao3", 10,10,33,nil)
    TestCreate("ci22", 220, 410, 56, nil)
    TestCreate("ci232", 220, 410, 56, nil)
    TestDone()
    collectgarbage()
    print ("memory used:"..collectgarbage("count"))
  • ops...!!!

    Well at least my code is not badly written! .. ;)

    thanks atilim... friendly as always!.
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
Sign In or Register to comment.