How to check if sprite is removed

Hi! I would like to make a simple garbage-collecting function because a lot of times I just remove sprites from the draw list and move on, but after some time the memory has loaded up with a ton of sprites removed from the draw list, but still existing in memory. After running the "playdate.graphics.sprite.getAllSprites" function, I want to check which one of the sprites is removed from the draw list and to get rid of that sprite from the memory.
If I wasn't understandable, which I would totally get, here's the current function:

function collectSpriteGarbage()
for k, v in ipairs(playdate.graphics.sprite.getAllSprites()) do
-- check if sprite is removed
-- delete sprite from memory
end
end

1 Like

Update: I have found an already existing collectgarbage() function, but I'm not sure if it'll work if I just remove the sprite and set it to nil

So, for people worndering later, this is what I did when loading every frame:
for k, v in ipairs(sprites) do
playdate.graphics.sprite.removeSprite(v)
v = nil
end
sprites = {}

(add all managed sprites to sprites)