Page 1 of 1

Thoroughly deleting an object

Posted: Fri Jan 15, 2021 1:07 pm
by Gunroar:Cannon()
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 ( 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):

Code: Select all

--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
    local bulls = lume.copy(self.bullets)
    for x, i in pairs(bulls) do
    self.entites = {}
    self.bullets = {}
    --destroying tiles
    self.allTiles = {}
    self.tiles = {}
    self.grid = {}
    GS.stacks = {}--?? = nil
    game.currentMap = nil = false
    self:unpause() = nil
    game.player = nil
    self.player = {}


Re: Thoroughly deleting an object

Posted: Tue Jan 19, 2021 6:29 am
by Gunroar:Cannon()
I also use bump.lua for entities and all tiles.

Re: Thoroughly deleting an object

Posted: Thu Jan 21, 2021 10:06 pm
by 4vZEROv
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.

Re: Thoroughly deleting an object

Posted: Sun Jan 24, 2021 11:21 pm
by dusoft
call: collectgarbage()

Re: Thoroughly deleting an object

Posted: Sat Jan 30, 2021 1:21 pm
by Gunroar:Cannon()
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.

Re: Thoroughly deleting an object

Posted: Tue Feb 16, 2021 9:05 am
by Gunroar:Cannon()
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 ... 3d7354eba0