Mac OS X的【内存】:Wired、Active、Inactive和Free

转自:http://www.19lou.com/forum-1658-thread-25902363-1-1.html

Mac的内存使用:Wired, Active, Inactive和Free

  

    ◇ Wired(联动): 系统核心占用的,永远不会从系统物【[内存】中驱除。

    ◇ Active(活跃): 表示这些内存数据正在使用种,或者刚被使用过。
    ◇ Inactive(非活跃): 表示这些内存中的数据是有效的,但是最近没有被使用。

    ◇ Free(可用空间): 表示这些内存中的数据是无效的,即内存剩余量!


当Free的【内存】低于某个key值时

    这个key值是由你的物理内存大小决定的,系统则会按照以下顺序使用Inactive的资源。

    首先,如果Inactive的数据最近被调用了,系统会把它们的状态改变成Active,并且在原有Active内存逻辑地址的后面;

    其次,如果Inactive的内存数据最近没有被使用过,但是曾经被更改过,而还没有在硬盘的相应虚拟[内存]中做修改,系统会对相应硬盘的虚拟内存做修改,并把这部分物理内存释放为free供程序使用。

    再次,如果inactive[内存]中得数据被在映射到硬盘后再没有被更改过,则直接释放成free。

    ◇最后如果active的内存一段时间没有被使用,会被暂时改变状态为inactive。

  

    所以,如果你的系统里有少量的free memeory和大量的inactive的memeory,说明你的内存是够用的,系统运行在最佳状态,只要需要,系统就会使用它们,不用担心。

    如果系统的free memory和inactive memory都很少,而active memory很多,说明你的[内存]不够了。当然一开机,大部分[内存]都是free,这时系统反而不在最佳状态,因为很多数据都需要从硬盘调用,速度反而慢了。



--------------------------------------------------------------------------------------------------------

以下转自:http://www.cnblogs.com/tony508/archive/2011/01/28/1946837.html

   相信大家做iPhone开发都遇到过内存吃紧的问题,最要命的是不知道究竟自己刚写的这段代码用了多少内存(被instrument骗过好多次了),下面贴出我常用的查看现有内存方法

#import 
#import 

- (double)availableMemory {
    vm_statistics_data_t vmStats;
    mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
    kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
    
    if(kernReturn != KERN_SUCCESS) {
        return NSNotFound;
    }
    //vmStats.wire_count
    //vmStats.inactive_count
    //vmStats.active_count
    return ((vm_page_size * vmStats.free_count) / 1024.0) / 1024.0;
}


官方的名词解释 

Free memory

This is RAM that's not being used.
 

Wired memory

Information in this memory can't be moved to the hard disk, so it must stay in RAM. The amount of Wired memory depends on the applications you are using.
 

Active memory

This information is currently in memory, and has been recently used.
 

Inactive memory

This information in memory is not actively being used, but was recently used.

For example, if you've been using Mail and then quit it, the RAM that Mail was using is marked as Inactive memory. This Inactive memory is available for use by another application, just like Free memory.  However, if you open Mail before its Inactive memory is used by a different application, Mail will open quicker because its Inactive memory is converted to Active memory, instead of loading Mail from the slower hard disk.
 

Used

This is the total amount of memory used.
 

VM size

This is the total amount of Virtual Memory for all processes on your Mac. 
 

Page ins / Page outs

This refers to the amount of information moved between RAM and the hard disk. This number is a cumulative amount of data that Mac OS X has moved between RAM and disk space.

Tip: Page outs occur when your Mac has to write information from RAM to the hard drive (because RAM is full).  Adding more RAM may reduce page outs.
 

Swap used

This is the amount of information copied to the swap file on your hard drive.

(更多内存使用信息可查阅苹果开发文档:Memory Usage Performance Guidelines )

你可能感兴趣的:(计算机系统)