代码之家  ›  专栏  ›  技术社区  ›  kennyc

如何在macOS下模拟内存不足的情况?

  •  3
  • kennyc  · 技术社区  · 6 年前

    iOS模拟器有这样一个功能,但我似乎无法在macOS下找到一个类似的功能。

    NSPurgeableData IOSurface 正在清除的句柄。

    2 回复  |  直到 6 年前
        1
  •  6
  •   l'L'l    6 年前

    上的工具 macOS 用于模拟内存不足的情况 memory_pressure

    sudo memory_pressure -S -l critical
    

    上面的命令模拟( -S -l

    名称
    memory_pressure(内存压力)--在内存上应用真实或模拟内存压力的工具 系统

    提要
    记忆压力[ -l -p 自由百分比][ - -l

    选择权
    施加真实或模拟内存压力(如果指定) 模拟参数),直到生成对应的低内存通知。支持的值为“警告”和“严重”。

     -p <percent_free> Allocate memory till the available memory in the system
     is <percent_free> of total memory. If the percentage of available memory
     to total memory on the system drops, the tool will free memory till
     either the desired percentage is achieved or it runs out of memory to
     free.
    
     -S Simulate memory pressure on the system by placing it artificially for
     <sleep_seconds> duration at the "warn" or "critical" level.
    
     -s <sleep_seconds> Duration to wait before allocating or freeing memory
     if applying real pressure. In case of simulating memory pressure, this is
     the duration the system will be maintained at an artifical memory level.
    

    描述
    对系统施加真实或模拟内存压力的工具

    另见

        2
  •  1
  •   TheDarkKnight    6 年前

    从代码中,您可以使用 setrlimit 用于控制应用程序中的系统资源消耗的函数。

    ulimit 允许控制从终端启动的资源