What kind of optimization patterns can be used to improve the performance of the garbage collector?
My reason for asking is that I do a lot of embedded software using the Compact Framework. On slow devices the garbage collection can become a problem, and I would like to reduce the times the garbage collector kicks in, and when it does, I want it to finish quicker. I can also see that working with the garbage collector instead of against it could help improve any .NET or Java application, especially heavy duty web applications.
Here are some of my thoughts, but I haven’t done any benchmarks.
- reusing temporary classes/arrays (keep down allocation count)
- keeping the amount of live objects to a minimum (faster collections)
- try to use structs instead of classes