The listView:cleanUp() code in the tableView.lua file does not properly free up all of the resources in the list. It is still calling the old item:remove(i) code instead of recursively removing everything in the group.
First, I suggest that a new API call be added to properly recurse through a Group to remove all of the items in it. The group:removeSelf() call does NOT recurse to the children items. This is a huge problem with much of the user-submitted code I have been looking at. People just don't really seem to understand memory management (even with the good articles available). I think Corona could be made more stable by addressing some of this in the core API.
In any case, I added the following function to tableView.lua (taken from the Director project)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | local function removeGroup( curGroup, level ) level = level or 0 if curGroup.numChildren then while curGroup.numChildren > 0 do removeGroup( curGroup[curGroup.numChildren], level+1 ) end if level > 0 then curGroup:removeSelf() end else curGroup:removeSelf() curGroup = nil return end end |
Btw, the line
local i
is not needed since Lua makes all "for" loops use local variables.
Also note the proper changes to reference the "self" variable instead of the hard-coded "listView" references that were in the original code.
Hi MPotter,
As a new user, I really appreciate the assistance you are providing in these Forums.
I am learning alot here but I agree that memory management is the thing I least understand. Coming from a Flash background, I haven't really dealt with this issue.
Plus I can't really figure out how to detect a 'memory leak'. In the Simulator? The Debugger?
It would be nice to see more info on this topic.
Greetings,
this is great stuff.. What I want to know is how do I call this cleanUp function. Since listView is local and so is currentTarget.
I added
function cleanUp()
currentTarget:cleanUp();
end
to tableView.lua but I am sure there is a smarter way ?
T.