Skip to content

GCMemoryInfo.MemoryLoadBytes does not reflect whats inside MEMORYSTATUS  #94565

@msedi

Description

@msedi

Description

Irecently came across an issue where I wanted to get rid of the windows API method GetGlobalMemoryEx method and switch to the GC.GetMemoryInfo() to make my applications more platfom-independent.

From the description of the GCMemoryInfo it says for GCMemoryInfo.MemoryLoadBytes.

On Windows, memory load is a field in the MEMORYSTATUS structure. It's a number between 0 and 100 that specifies the approximate percentage of physical memory that's in use (0 indicates no memory use and 100 indicates full memory use). Corresponding information is given on other operating systems.

When looking at MEMORYSTATUS in https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-memorystatus this seems to be correct. When I call the GC.GetMemoryInfo() though, the value in GCMemoryInfo.MemoryLoadBytes is not between 0 and 100.

Looking deeper in it, it seems more that the value contains MEMORYSTATUS.dwAvailPhys.

Is this a known behavior?

Reproduction Steps

Simply call GC.GetMemoryInfo() and compare to the corresponding windows GetGlobalMemoryStatus API call.

Expected behavior

GCMemoryInfo.MemoryLoadBytes should contain the values as described in the docs.

Actual behavior

GCMemoryInfo.MemoryLoadBytes contains MEMORYSTATUS.dwAvailPhys

Regression?

Not sure if this has ever worked. I haven't tried before.

Known Workarounds

Stay with the GetGlobalMemoryStatus API method.

Configuration

.NET7 / Visual Studio 2022

Other information

No response

Metadata

Metadata

Assignees

Labels

area-GC-coreclrdocumentationDocumentation bug or enhancement, does not impact product or test code

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions