Per-thread memory management in C#

后端 未结 3 1096
谎友^
谎友^ 2020-12-16 07:19

Continuing the discussion from Understanding VS2010 C# parallel profiling results but more to the point:

I have many threads that work in parallel (using Parallel.Fo

3条回答
  •  别那么骄傲
    2020-12-16 08:15

    The garbage collector does not allocate memory.

    It sounds more like you're allocating lots of small temporary objects and a few long-lived objects, and the garbage collector is spending a lot of time garbage-collecting the temporary objects so your app doesn't have to request more memory from the OS. From .NET Framework 4 Advanced Development - Garbage Collection:

    As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. However, memory is not infinite. Eventually the garbage collector must perform a collection in order to free some memory.

    The solution: Don't allocate lots of small temporary objects. The page on Garbage Collection and Performance might also be helpful.

提交回复
热议问题