I'm working on a GUI-based particle system and I've been introduced with a bit of an issue regarding the table handling the particles themselves.
My Issue
I have a table, particleList, that holds the data of each individual particle active every frame. I'm inserting data into this table using table.insert, meaning each new element shows up after the last item. The issue lies where the particles' lifespan ends, when I want the handler to remove the particle itself and stop handling it altogether (removing it from the table).
Most commonly, the particles' lifespan would run out in order from first created to last created, meaning it's almost always the first particle in the table that's removed. My first plan was to use table.remove to remove the particles from the table, but I was told by reputable sources that every element after the removed has to be copied and shifted backwards. As I'm going to be handling up to hundreds of particles at a time, I fear this will be too hard on the game to do this on a frame-by-frame basis.
My Hypothesis
My first idea to fix this was to set removed particle data to nil instead of using table.remove. The problem here is pretty obvious: there will be many holes left inside the table, especially over time.
My second idea was to have a separate function that runs at a different, much slower interval to clear the table of any nil values using a set of table.remove calls, possibly every few seconds. Though, I fear this is also too hard on the game as it's only condensing the remove calls into one place.
My third and current idea is to insert particles into the holes in the array rather than using table.insert. Though I'm not sure how painful it would be on the game itself to search through the table for the nil values every time a new particle is created. This seems like the best solution to me thus far.
My Question
Is there a definitive way to do this? My current plan is to use the third idea but if there's a better way to handle this or one of my ideas is simply the best, I'd appreciate this being made clear to me.
Thank you!

2 comments
You want to make ParticleEmitters in a GUI?
Essentially, though this isn't the question at hand