I want to delete a map object that holds a bunch of entities and I have an idea but it still leaves the map object floating around with a few mb after I destroy it and the framerate goes down a little too.
1.Please just check it over if this is ok and notify if you see any possible problem( I use hump's gamestate (https://github.com/vrld/hump/blob/master/gamestate.lua)so do I need to do anything specialwith that)
2.Is there anyway to check whether an object is still referenced and where?.
Here's the destroy function( I destroy objects so space will be freed in the object pool for that object):
--GS = hump.gamestate btw
function Map:destroy(destroyPeer)
self.isOld = true
--destroying entities to free up space in
--object pools
local ents = lume.copy(self.entities)
for x, i in pairs(ents) do
if i ~= game.player then
i:destroy()
end
end
local bulls = lume.copy(self.bullets)
for x, i in pairs(bulls) do
i:destroy()
end
self.entites = {}
self.bullets = {}
--destroying tiles
self.allTiles = {}
self.tiles = {}
self.grid = {}
GS.stacks = {}--??
game.map = nil
game.currentMap = nil
self.active = false
self:unpause()
self.player.map = nil
game.player = nil
self.player = {}
lume.clear(self)
end
The risk I took was calculated,
but man, am I bad at math.
A table will only be garbage collected if there is no reference of it anywhere is the program. (not counting weak tables)
So a reference to your map is still somewhere in your code and keep it alive.
It's probably inside your bump.lua code, I believe you initialize the bump tables with some references if I remember correctly.
Ah, I found it. Hump gamestate had a local called stacks so it couldn't be accessed and the class couldn't be deleted. I accessed it by making it part of the Gamestate class. thnx.
The risk I took was calculated,
but man, am I bad at math.
I made this function to find any references to an object (which I still had due to some accidentally global declared tables) so you can flush it out, and that really fixed it for me https://love2d.org/forums/viewtopic.ph ... 3d7354eba0
The risk I took was calculated,
but man, am I bad at math.