Game graphics stutters after deleting old objects

Hey, so I’ve been making a game where these falling obstacles will be made and you have to dodge your character out of the way. So, for each falling item I create a new class for it, and store it in a table. As it falls down, I run an if statement seeing if that object is within bounds, if it isn’t, it will remove the item from the table and then call collectgarbage to assure there aren’t memory leaks. However, when I implemented this I’m noticing stuttering graphics after an object gets destroyed, it would appear it’s always the object above that one, and only that one. Not exactly sure how to fix this, I think this happened to me before in the past but I can’t remember if there were any solutions. Can provide with more information if needed. Thanks!

@Programmer1500 I think your problem is deleting the objects from the table while you trying to display objects in the table. If you delete an object from the table going from beginning to end, then the objects after the deleted one gets skipped because the objects in the table shift down. The way to fix that is to go thru the table from end to beginning, that way you display objects before the table gets rearranged. Or you can flag the objects to be deleted then in another loop delete them from the table.

Thanks dave! I’ll try this.