0

I'm using .Net 4.0 and i need to create a lot of images during my program works. As far as i understand images stored in LOH. Is Image.Dispose() method release memory in LOH? I tried to use profiler and i saw a lot of SOH cleans by GC, but memory usage of application still increase. And all memory releases only on if i call

GC.Collect(); 
GC.WaitForPendingFinalizers();

So it looks like dispose method of image doesn't release LOH memory.

Alex
  • 77
  • 7
  • 4
    `IDisposable` has *almost nothing* (at least directly) to do with the GC, so basically: no. Note also that the GC doesn't *even attempt* to aggressively hand memory back to the OS for no reason. What makes you think there is a problem? – Marc Gravell Mar 15 '18 at 15:42
  • @MarcGravell I did some stress test for my app and i see, that a memory usage increase during this test. Profiling gets nothing because all memory releases when i do snapshot. So i think, that problem with my images, that stored in LOH. This leads to out of memory exception – Alex Mar 15 '18 at 15:51

1 Answers1

1

IDisposable is a mechanism of managing the lifetime of unmanaged resources (either unmanaged memory or other things, like file handles). The LOH is for managed memory. So yes, calling Dispose will most likely do nothing at all to your managed heap usage since the two things have nothing in common.

Joey
  • 344,408
  • 85
  • 689
  • 683