.NET fragmentation heap when using MSMQ async IO

I have an application that reads from a large number of MSMQ queues (about 10,000 at the moment). I use queue.BeginPeekUInt32.MaxValue with a timeout to get the message from the queue. When a message appears in the queue, I process it and call it queue.BeginPeekagain. So I listen to all the queues, but message processing is done in the thread pool.

I noticed that memory usage is slowly growing (two weeks of work cause growth from 200 MB to 800 MB). After examining the dump file, I see a typical heap fragmentation image with many free objects (some of them are about a few megabytes in size). And objects are fixed between the holes.

This is apparently a common situation when dealing with unmanaged code calls that create pinned objects. But I did not find a solution on the Internet.

So, is .NET's memory management so clean that it doesn't even complete such simple scripts, or am I missing something?

Edit: I did some research in sample applications. Holes (free memory zones, so-called free objects) between fixed objects are reused by the GC when allocating memory for new objects. But in my production application, pinned objects live for a long time, and they finally appear in the second generation with holes in between (because the GC just shifts the boundary that separates the generations). Since I really have few normal long-lived objects, I see these holes in the second generation in the dump file.

, 10000 * ( ). (10000 - , ). , . - .

, .NET ? (, ). , , , .

+5
2

MSMQ, , API. BeginPeek , API. , , BeginPeek , .

, , , - , BeginPeek, . .

+4

, , , - BeginPeek , . EndPeek BeginPeek. , , , , , ( , , ). , .

+1

All Articles