24

Is it possible to determine actual RAM size of an iOS device?

Referring to this question Determining the available amount of RAM on an iOS device we can determine the available free memory but how to get the actual total size.

Community
  • 1
  • 1
Sohaib
  • 10,941
  • 9
  • 32
  • 34

4 Answers4

67

The simplest solution to find total RAM in a device is to use NSProcessInfo:

Objective C:

[NSProcessInfo processInfo].physicalMemory

Swift 3:

NSProcessInfo.processInfo().physicalMemory

Swift 5:

ProcessInfo.processInfo.physicalMemory

Note: physicalMemory gives us the information at bytes, to calculate GB, divide by the constant 1073741824.

As documented here.

Woodstock
  • 22,184
  • 15
  • 80
  • 118
2

Slight change for Swift 3: ProcessInfo.processInfo.physicalMemory

Swindler
  • 802
  • 10
  • 9
1

Following code is to get memory in GB

// For getting size in GB

     [NSProcessInfo processInfo].physicalMemory / (1024.0 * 1024.0 * 1024.0)];

// Swift Version

      NSProcessInfo.processInfo().physicalMemory/(1024.0 * 1024.0 * 1024.0)
s Hetul
  • 94
  • 6
0

The answer is right there in the top answer of the question you linked:

natural_t mem_used = (vm_stat.active_count +
                      vm_stat.inactive_count +
                      vm_stat.wire_count) * pagesize;
natural_t mem_free = vm_stat.free_count * pagesize;
natural_t mem_total = mem_used + mem_free;
NSLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total);
Community
  • 1
  • 1
Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156