katlicia wrote: ↑Thu Feb 15, 2024 10:21 pm
And a really quick question: If off screen objects are using memory like "setting a pipes X coordinate to -100" how could you actually destroy them once they are no longer used.
The Lua language standard defines a memory managed environment, and the LuaJIT interpreter used by Löve follows that.
Any objects (like tables, strings, userdata) that are not visible to any parts of your code, get garbage collected. So object deletion has to do with visibility within code.
This means that any time some object, like a table for example, goes out of scope (has all references to it lost, effectively becoming inaccessible to any parts of your code), it's automatically marked to be destroyed for you, eventually freeing its memory.
Edit: for example, you have myVariable = myTable, and at some point you have myVariable = otherTable. After that new assignment, if nobody else has a reference to myTable, then it'll automatically be destroyed.
If you keep pipe tables in some bigger "allPipes" table, then removing an item from that allPipes table should eventually let it be garbage collected, provided that there are no other tables or variables holding a reference to that pipe table of course.
But a suggestion is to not delete pipes that have moved off screen -- rather, just reuse them as needed, giving them new coordinates that make them appear as they are new pipes coming up ahead.