Skip to content

fix(device_info_plus): correct iOS availableRamSize overflow above 4 GB - #4038

Open
martinusgalih wants to merge 1 commit into
fluttercommunity:mainfrom
martinusgalih:fix/device-info-ios-available-ram-overflow
Open

martinusgalih wants to merge 1 commit into
fluttercommunity:mainfrom
martinusgalih:fix/device-info-ios-available-ram-overflow

Conversation

@martinusgalih

@martinusgalih martinusgalih commented Dec 5, 2026 •

Copy link
Copy Markdown

Description

IosDeviceInfo.availableRamSize on iOS is computed as:

natural_t mem_free = vm_stat.free_count * page_size;
return mem_free / 1048576;

natural_t is 32-bit, so the byte count is truncated once free memory passes 4 GB (for example, 6 GB free is reported as 2048 MB). This stores the byte count in a uint64_t before converting to megabytes, as proposed in the issue. The returned unit (MB) and the Dart int field are unchanged.

Related Issues

Testing

  • flutter analyze, dart format --set-exit-if-changed and flutter test (11 tests) pass for the package.
  • The changed lines compile cleanly with clang against the iPhoneOS SDK with -Wshorten-64-to-32; the old line reproduces the warning quoted in the issue.
  • Not tested on a physical device with more than 4 GB of free RAM, and the iOS integration tests were not run.

Before / After

Before and after: clang warns about the 32-bit truncation on main and is clean with this change; with 6 GiB free the old code reports 2048 MB

Output as text

clang -target arm64-apple-ios13.0 -Wshorten-64-to-32 -fsyntax-only, before:

warning: implicit conversion loses integer precision: 'vm_size_t' (aka 'unsigned long') to 'natural_t' (aka 'unsigned int') [-Wshorten-64-to-32]
    natural_t mem_free = vm_stat.free_count * page_size;

After: no warnings.

Same arithmetic in a small C program, 6 GiB free (393216 pages x 16 KiB):

before: 2048 MB
after:  6144 MB

Disclosure: this change was prepared with AI assistance.

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[device_info_plus] iOS availableRamSize is wrong when more than 4 GB is free

1 participant