Cleanup Confusion
I have some block objects that I need to get rid of when a row is complete in my tetris remake. I know to set them to "null", but how do I completely remove an instance of a class from existence?
In this case, they will automatically get cleaned up, once you have totally stopped using them. This is called "garbage collection" and it makes things a lot easier.
As soon as all references to an object are gone, it gets garbage collected. Any time you pass an object to a function, place it in an array, etc. a reference gets created. (Note that, when calling a function, the reference is cleaned up automatically when the function returns, so you don't have to worry about that.) All you need to do is make sure that each reference is removed, and the object will be cleaned up for you.
As soon as all references to an object are gone, it gets garbage collected. Any time you pass an object to a function, place it in an array, etc. a reference gets created. (Note that, when calling a function, the reference is cleaned up automatically when the function returns, so you don't have to worry about that.) All you need to do is make sure that each reference is removed, and the object will be cleaned up for you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement