David Wohlferd
David Wohlferd

Reputation: 7528

Is GC.AddMemoryPressure appropriate when using Marshal.AllocHGlobal?

Does

IntPtr ip = Marshal.AllocHGlobal(size);

implicitly add memory pressure (a la GC.AddMemoryPressure)? True it's allocating unmanaged memory, but it doesn't do it "out of the sight of CLR." I could see an argument for either adding or not adding.

It seems like it could (and perhaps should). But I need to know what it actually does.

Upvotes: 1

Views: 277

Answers (1)

mjwills
mjwills

Reputation: 23975

As per the source code (or for .NET Core), no it doesn't call GC.AddMemoryPressure.

Upvotes: 2

Related Questions