-1

I have an vb.net application I distribute to my analysts – We assign perhaps 100 200MB images at a time. The app sequentially opens the large jpg image using GDI+ and the image is placed in the LOH. I scan each pixel looking for data. - when done I dispose the image and use GC.collect. But this does not clear the LOH, and as a result the LOH keeps increasing until the app crashes. A work around is to chop the assignment into 25 instance chunks, but this is risky as our analysts often do this late at night – perhaps after a beer or 2.

The C# construct is

 GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce

but there is no GCSettings available in vb.net

My vb.net code is

    loadedImage.Dispose()
    MasterImage.Dispose()

    GC.Collect()
    Finalize()

But I cannot find a vb.net method to force the LOH compaction

When done

Can you help?

J...
  • 30,968
  • 6
  • 66
  • 143
Rfrank
  • 51
  • 5
  • Not possible if targeting < 4.5.1, also [should you be using compaction](https://www.red-gate.com/simple-talk/dotnet/net-framework/large-object-heap-compaction-should-you-use-it/)... – Trevor Mar 27 '19 at 20:17
  • If you don't want to use a memory profiler then you just need more beer. Project > Properties > Compile tab > untick the "Prefer 32-bit" checkbox. – Hans Passant Mar 27 '19 at 22:20
  • Hi and thanks - I do have t32-bit unchecked, now on .net 4.6.1 I like memory profiling better than beer, so 2 snapshots at some distance from each other showed almost no change in heap sizes but the process memory went from 681MB to 15.3 GB - so about 350MB per image is not released back to the system. I will try adding a 'Finally to the single try/catch block, but the catch is never used. Looking at GC not releasing . . . topic now – Rfrank Mar 28 '19 at 20:20

1 Answers1

0

GCSettings.LargeObjectHeapCompactionMode was added in .NET 4.5.1. It exists in VB.NET as well as C#. You're probably targeting a lower version of the .NET runtime. If you want access to this feature you will need to compile against a framework version of 4.5.1 or higher.

This likely won't solve the underlying problem, however. Your leak may not even be where you think it is. Profiling your application with an allocation profiler is the best way to track down resource leaks. Without a Minimal, Complete, and Verifiable example, it is difficult to guess where your application may be going wrong.

J...
  • 30,968
  • 6
  • 66
  • 143
  • Hi and thanks - I was using the v4.0 which was available in 2007 when i first wrote the app, I went to 4.6.1 and found the GCSettings and used it in a runtime construct - it runs - but is not solving the problem. For testing - i have a 4 image set - so I will expand the data set to a full production run and retest. It is possible I do not understand the issue . Is there a way to see the contents of memory by variable name? – Rfrank Mar 27 '19 at 20:59
  • @Rfrank I think that's a topic for a follow-up question. See : [What is the the best way to ask follow up questions?](https://meta.stackoverflow.com/q/266767/327083) – J... Mar 27 '19 at 22:04