memory and garbage collecting


Important thing is not to lock memory when using objects which are connected to other objects and will be released while still the other object exists.

Example can be this : i have a scene object. In the scene object i put in the list of the scene an car object. The car object also refers back to scene object so it can easily for some reason get there when needed. Cool? Yes, but also makes memory feel bad. The garbage collector will not release the car properly because it is connected to scene which exists until somewhere inside perhaps a game object you disconnect the scene object too. Which is ok until you find out that you spawned between some minutes maybe around 5M objects of cars.

So remember to clean the object when destroyed by disconnecting from scene. object.parent_scene = nil would be enough.

I did some testing and it seems that was the reason of some problems with memory growing. Also there is something like weak table reference (read on lua web about it) and the object class definition i used did not know about that. The weak table when released did not watch if there are any connection to scene and just released the car itself. Which is good i think… ehm, if i did some mistake write on the conversation board under this text.

So long until next time when i find something usefull.

Leave a comment

Log in with itch.io to leave a comment.