[AS3] Insight needed, specific garbage cleaning

Hi,

I won’t post some code right now cause I don’t really feel its needed. Anyway, I’ve been working with my A* pathfinder on and off for the past month (update from previous AS2 version) And while the pathfinder in itself is done, I introduced some new features to it recently, one being a queue system (Don’t ask me how poor the thing was before…)

The thing with the queue system is that, when a path is added to be searched, it returns an ID, normally a uint, this is because, when the path calculation is done, it starts with the next path straight away (if there are any in the queue) so the path just completed would have to be saved somewhere, naturally its saved in an array.

Now what is the problem you ask? Cleaning this array, I mean, if it’s not reset, it would eventually reach its limits. I know that’s pretty unlikely unless I’ll be continuously running path calculations for the next hour, But there’s also the issue of loads of data stacking up, which would inevitably suck loads of memory.

Why is it hard to clean it? Ok so, since it keeps running calculations according to the queue, and it saves the paths in the array (due to the fact that it might not be retrieved straight away), so what if I happen to reset the array when a path has not been retrieved already? I mean, there could be way more than one path that has not been retrieved yet, if say, 40 paths were trashed instantly, it would call for 40 new paths in an instant, I’m not saying this could cause slowdowns, but rather delays, since it could take a few ms to calculate a new path.

The only solution I could think of right now is to implement a ‘turn off’ for the path calculating until the path array is empty (being able to clean it without losing anything). But, there is nothing that says the path even will be retrieved, so there could be small leftovers which will just sit there. I could also make a internal timer that will remove the paths if they have not been retrieved for a certain amount of time, which would eliminate the previous scenario.

I’ve also thought of an alternative to the array, which would be an object, using hash strings as keys to store the path data, and once retrieved just be removed. (There were some complications to doing this with an array, due to the fact that the IDs for paths were directly linked to the position in the array).

Bet that was loads of bull to read, any tips anyone?

Thanks for reading,

Matt