Hi all,
I’m having a memory leak problem, and i can’t figure out how to fix it. I think it has to do with tables.
I’m checking my memory at regular points to keep an eye on it, and found out that Texture memory is stable, all the objects/sprites are released as soon as i reload a level, but memory usage increases.
In a nutshell, i load a level with objects, and create a table to handle and assign properties:
-- level.lua
local platform = {}
loader = LevelHelperLoader:initWithContentOfFile("level" .. Level .. ".plhs")
loader:enableRetina(false)
loader:instantiateObjectsInGroup(physics, localGroup)
local allSpr = loader:allSprites();
for k, v in pairs (allSpr) do
if 1 == v.tag then -- Blue
NumberOfPlatforms = NumberOfPlatforms + 1
platform[NumberOfPlatforms] = v.coronaSprite
platform[NumberOfPlatforms].Type = "Blue"
platform[NumberOfPlatforms].isDown = false
platform[NumberOfPlatforms].numFrames = v.coronaSprite.numberOfFrames
platform[NumberOfPlatforms].curFrame = 1
NumberOfBlueBoxes = NumberOfBlueBoxes + 1
print("Blue Box")
platform[NumberOfPlatforms]:addEventListener( "touch", RemovePlatform )
end
if 2 == v.tag then -- Green
NumberOfPlatforms = NumberOfPlatforms + 1
platform[NumberOfPlatforms] = v.coronaSprite
platform[NumberOfPlatforms].Type = "Green"
platform[NumberOfPlatforms].isDown = false
platform[NumberOfPlatforms].numFrames = v.coronaSprite.numberOfFrames
print("Green Box")
platform[NumberOfPlatforms].curFrame = 1
end
if 3 == v.tag then -- Red
NumberOfPlatforms = NumberOfPlatforms + 1
platform[NumberOfPlatforms] = v.coronaSprite
platform[NumberOfPlatforms].Type = "Red"
NumberOfRedBoxes = NumberOfRedBoxes + 1
platform[NumberOfPlatforms].isDown = false
platform[NumberOfPlatforms].numFrames = v.coronaSprite.numberOfFrames
platform[NumberOfPlatforms].curFrame = 1
print("Red Box")
--print (string.format("%s", platform[NumberOfPlatforms].y))
end
end
Before i reload the level (switching to loading.lua, who loads level.lua again) i cleanup every object, timer, eventListener.
The texture Memory is stable, so all texture objects a freed from memory. But i think the table 'platform’is causing the problem.
I tried cleaning up the table with platform = nil, but that gives me even more errors.
Is there any method to empty a table and its contents from memory?
I tried to declare the table like:
platform = {}
instead of
local platform = {}
and that really seems to help, but again, it gives me lots of NIL value errors after loading the level. So im totally confused.
[import]uid: 50459 topic_id: 13119 reply_id: 313119[/import]