Re: Problem with memory leaks

From: Fabian Schmied (REMOVETHISfabianDOTschmied_at_fhs-hagenbergDOTacDOTat)
Date: 05/15/04

Date: Sat, 15 May 2004 13:39:25 +0200

Thomas schrieb:
> Now I managed to drop the memory-leaks to 5% (from 800 kb to 40kb) by
> calling the GC manually, everytime I use the device.
> But I don't think, that this is the right solution, because managed code
> should garbage-collect by its own.
> I write this here, because I think this could be helpful to solve the
> problem.

Okay, your application will be automatically garbage-collected when
memory is used up (or earlier, if your application is idling). This
means GC will eventually kick in and free all the memory (unless you are
holding references to dead objects). However, as a game developer, you
should try to make sure that GC isn't performed too frequently.
Certainly not once per device usage. Look at the memory allocations you
seem to be making on a per-frame basis. Are they really necessary? Could
you pool objects, i.e. create them once and reuse them whenever possible?

If you aren't sure where the allocations are being made, try to comment
out all of your code and gradually uncomment again, until it starts
eating memory again.