This happens if you have an enormous Infant Mortality Rate, which is to say, way too many variables being destroyed in a frequently used function. An example that happened to me: I tried to base my geometry objects on a super-simplified version of Java2d, and Java is notorious for using objects for absolutely everything, even when methods would make much more sense. So, if I needed to do a test with a flipped or translated version of a shape, I'd have to make a new shape every time. At worst, this meant that a single frame of AI could result in hundreds of shapes being rapidly created and destroyed, just for one enemy to make one choice. Just 10 active objects could cause a garbage collector warning, if I let it play too long.
In my case, I became more willing to make shapes easily change from the interface, and tried to reuse a small set of them. This brought it down to double digits for the average scene, only getting into the hundreds when lots of projectiles were active at once. (I might also have used some not-entirely-thread-safe tricks in AI at one point. Not looking forward to porting that to a threaded language. )
So, if you are, say, creating a massive 3d array every frame, or something like that, that'd be the problem. Look for ways to accomplish the same things without creating so many variables, or so big arrays, etc. If you're having trouble finding where these variable graveyards are happening, maybe keep a global variable to count how many objects have been destroyed, and give your classes destructors that increment it? Ex, in an enemy class, you might do something like:
~enemy() { deadenemies++; }
Then set a key or command to report the value of deadenemies, or copy it to the clipboard every frame, or whatever works best for you.
At its worst, I was logging before and after all suspect bits of code, to try and hunt down exactly what was happening. I emphasize the value of backing up your code often, but especially in a situation like this, where it's easy to make so many changes while reducing the IMR that you accidentally break something and can't unravel how.
TLDR: look for places where you create too many temporary variables and objects on a frequent basis, and find a way to reduce that number.
看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
George... Don't do that.