Skip to content

On macOS Process.PrivateMemorySize64 returns 0 #105665

Closed

Description

@nwoolls

Description

Accessing Process.PrivateMemorySize64 on macOS returns 0. This was initially reported, and fixed, for Linux here. Follow-up comments mention macOS but the issue was closed.

The implementation of AssertNonZeroAllZeroDarwin seems to indicate this is acknowledged, if not by-design. But the XML comments for Process.PrivateMemorySize64 doesn't mention any such limitation.

Not sure if this is a bug or feature request, but I'd love to see this implemented for macOS. We're trying to troubleshoot some memory usage but coming up short in our dev environments because of this.

Reproduction Steps

mkdir app-macos-PrivateMemorySize64
cd app-macos-PrivateMemorySize64
dotnet new console
using System.Diagnostics;

var process = Process.GetCurrentProcess();
Console.WriteLine(process.PrivateMemorySize64);
dotnet run

Expected behavior

Outputs "the amount of private memory, in bytes, allocated for the associated process".

Actual behavior

Outputs 0.

Regression?

No

Known Workarounds

None

Configuration

dotnet --version
8.0.303
sw_vers
ProductName:		macOS
ProductVersion:		14.5
BuildVersion:		23F79
uname -a
Darwin nathanialsmbpm2.lan 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 arm64

Other information

No response

Activity

  1. added
    untriaged
    on Jul 29, 2024
  2. dotnet-policy-service commented on Jul 29, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
    See info in area-owners.md if you want to be subscribed.

  3. added
    os-macos
    needs-further-triage
    and removed
    untriaged
    on Jul 30, 2024
  4. added this to the Future milestone on Jul 30, 2024
  5. added
    help wanted
    on Jul 30, 2024
  6. ShawnWu33 commented on Oct 6, 2024

    @ShawnWu33

    Hi, did a bit investigation on this. Apology first if the terminologies are not accurate enough as I am new to this community.

    TL;DR

    The private memory size of a process is not exposed in macOS (OSX) SDK, hence the value remains default int value as 0;

    Investigation details

    1. The Process.PrivateMemorySize64 having a getter function which will first ensure process information being retrieved.

      public long PrivateMemorySize64
      {
      get
      {
      EnsureState(State.HaveProcessInfo);
      return _processInfo!.PrivateBytes;
      }
      }

    2. When process information did not existed, it trigger ProcessManager to retrieve the process information.

      if (_processInfo == null)
      {
      if ((state & State.HaveNonExitedId) != State.HaveNonExitedId)
      {
      EnsureState(State.HaveNonExitedId);
      }
      _processInfo = ProcessManager.GetProcessInfo(_processId, _machineName);

    3. The process manager invoke Interop.libproc.GetProcessInfoById(pid) to get process information.

      Interop.libproc.proc_taskallinfo? info = Interop.libproc.GetProcessInfoById(pid);
      Which eventually hitting macOS libproc API proc_pidinfo
      int result = proc_pidinfo(pid, PROC_PIDTASKALLINFO, 0, &info, size);

    4. Per macOS libproc header file proc_info.h (screenshot attached), the response from that API incldues only virtual memory size and resident memory size. Hence the field PrivateBytes in ProcessInfo is not assigned, remains default value.

    image

    Postscript

    This issue is known from very first commit of ProcessManager.OSX, It is a comment there mentioning fields didn't being assigned as not available in macOS.

    {
    // Set the values we have; all the other values don't have meaning or don't exist on OSX
    Interop.libproc.proc_taskallinfo temp = info.Value;
    procInfo.BasePriority = temp.pbsd.pbi_nice;
    procInfo.VirtualBytes = (long)temp.ptinfo.pti_virtual_size;
    procInfo.WorkingSet = (long)temp.ptinfo.pti_resident_size;
    }

    So I don't see a proper fix available at curren time point.

  7. nwoolls commented on Jul 23, 2026

    @nwoolls
    ContributorAuthor

    @adamsitnik I've staged a PR that addresses this shortcoming on macOS.

  8. added a commit that references this issue on Aug 19, 2026
    588a87f
  9. modified the milestones: Future, 12.0.0 on Aug 19, 2026
  10. removed
    help wanted
    needs-further-triage
    on Aug 19, 2026
  11. locked and limited conversation to collaborators on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions