Of course, pl = nil solves all the problems
But, for example, for bullets I have such code:
Code: Select all
if love.mouse.isDown("l") then
bullet:new(hostPlayer) --hostPlayer is a parent object
end
So bullet:new does return a table, but it is ignored. Instead, bullet is added to objList:
Code: Select all
table.insert(objList, self)
self.id = table.maxn(objList)
and then, when its time to destroy a bullet (it comes after 1.5s of life), I simply remove it from the table:
Code: Select all
table.remove(objList, self.id)
-- shifting ids of other objects:
for j = self.id + 1, table.maxn(objList) do
objList[j].id = objList[j].id - 1
end
self = nil
But memory doesnt seem to be freed. In fact, with every new bullet the game consumes more and more memory despite the fact, that every bullet lives 1.5s.