Note that there are some explanatory texts on larger screens.

plurals
  1. PO.Net Memory Management Issue : Objects Stuck in Generation 2
    primarykey
    data
    text
    <p>I have profiled my App w/ VS2010 profiler, with object lifetime collection enabled.<br> I was heavilly surprised to see that most instances of a particular struct named "Record" are collected by the GC as Gen 2 instances. I am very upset, as instances of "Record" struct should live less than 500ms each (theoretically). </p> <p>These structs are simple time series data of 6xInt32 or so, that are read on the flow, Queued/Dequeued in a Queue having a size of 1000, passed to a processor that fires some logic depending on those few millions "Records" sequentially. I do not need to keep more than 50 records at a time.</p> <p>So my question is : Why could these object live long enough to mainly end up as Second Generation references, and what could I do to ensure they REALLY get dumped off after each computation.</p> <p><em><strong>EDIT :</em></strong> I am asking this because I have noticed a drastic performance dropdown for bigger sample sizes (i.e Records Numbers) : if N take T minutes, 2N takes 2,5T minutes or so, and so on.<br> So there is obviously a leak somewhere.</p> <p><em><strong>EDIT 2 :</em></strong> My Bad : Creating a struct instance cannot cause a garbage collection I've changed it to classes and did not notice any significant improvement so far. I'll run the profiler again with classes this time not structs) and see what it gives</p> <p><em><strong>EDIT 3 :</em></strong> Many answers suspect Boxing/Unboxing to take place somewhere. I DO use typed generic collections and typed Queues. And "Records" are never attached to any class as members. They are individually handled by events. The ex-Struct (Now Class) implemented an interface and was casted by it when called (this is rather common usage) and I dropped off that interface. No improvement.</p> <p><em><strong>EDIT 4 :</em></strong> I have run again the profiler, replacing struct by class. I have the same results : <br><strong>most instances of <em>CLASS</em> "Record" still end up being collected as Gen2 instances</strong></p> <p><em><strong>EDIT 5 :</em></strong> Producers of the Record classes are many parallel <strong>BackGroundWorkers</strong> (Byte Readers), and there is one Consumer Thread that dispatches the Records to other methods after performing a few checks. Besides I use <strong>Events and Delegates</strong> to communicate between the different parts. I do not unregister those events because they are useful all along the process (I may be wrong on that point)</p>
    singulars
    1. This table or related slice is empty.
    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