Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET Heap fragmentation when using MSMQ async IO
    primarykey
    data
    text
    <p>I have an application that reads from large amount of MSMQ queues(about 10000 at the moment). I use <code>queue.BeginPeek</code> with UInt32.MaxValue timeout to receive message from queue. When the message appears in queue, I process it and call <code>queue.BeginPeek</code> again. So I listen to all the queues, but message processing is done on Thread Pool. </p> <p>I noticed that memory usage slowly grows(two weeks of work cause growth from 200 MB to 800 MB). After investigating the dump file I see typical heap fragmentation picture with many free objects (some of them have size about several megabytes). And there are pinned objects between the holes.</p> <p>This seems to be common situation when working with calls to unmanaged code, that create pinned objects. But I did not find any solution in the internet. </p> <p>So is memory management in .NET so pure, that it does not allow to complete even such simple scenarios, or I miss something?</p> <p><strong>Edit :</strong> I've made some investigations in sample applications. The holes(free memory zones, so called free objects) between pinned objects are reused by GC when allocating memory for new objects. But in my production application, pinned objects are long living, and they finally appear in 2nd generation with the holes between them(because GC just shifts the border which separates generations). As I have really little normal long-living objects, I see this holes in 2nd generation in dump file. </p> <p>So memory consumption of my application can grow to 10000*(average size of the hole). (10000 is the number of queues that can also increase in future). I have no ideas how to fix this at the moment. The only way is to restart application from time to time.</p> <p>Once again I can only ask, why .NET does not have separate heap for pinned objects? (maybe this is newbie question). At the moment I see that calling async operations that work with unmanaged code can cause memory issues.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload