Well, basically you have to cut down on the garbage collector. There are certain “patterns” that do a lot of work.
- Avoid having multiple objects with finalizers. Finalizers impose additional work on the garbage collector, because an object with a finalizer must be collected twice.
- Avoid the “midlife crisis” .. NET GC (on the desktop) is a GC generation. When the object survives in the first collection, but soon "dies", GC did a great job for nothing. (transition to the second generation, collecting again, etc.). Therefore, try to optimize the life time of your objects so that they either die quickly or survive for a long time.
- Reduce unnecessary distributions. For example, using the value type wisely. Or do the work in a less intense way.
So, in your case, I think that you or you have a “middle-aged” crisis with short lists. Or you just select a list like crazy.
In the first case: try to reduce the life of the lists. I can’t say what the solution looks like for your application.
In the second case: try to avoid highlighting so many lists. Maybe you can use the correct value types? Or fixed size arrays? Or change the structure of the code so that less lists are needed?
In any case, I would recommend commenting on your application and see how much memory you allocate and how much you can collect in the first generation.
source share