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

标签 xcode macos cocoa memory-management appkit

在开发和调试 macOS 应用时,有没有办法模拟系统范围的“内存不足”事件或通知?

iOS 模拟器有这样的功能,但我似乎无法找到 macOS 下的等效功能。

我有兴趣模拟低内存情况,以了解像 NSPurgeableDataIOSurface 这样的类如何处理被清除。

(除了编​​写一个不断分配内存的简单应用程序...)

最佳答案

macOS 上的工具用于模拟内存不足的情况,为 memory_Pressure(示例):

sudo memory_pressure -S -l critical

上面的命令模拟 (-S) 临界级别 (-l 临界) 的内存压力。

NAME
memory_pressure -- Tool to apply real or simulate memory pressure on the system.

SYNOPSIS
memory_pressure [-l level] | [-p percent_free] | [-S -l level]

OPTIONS
-l Apply real or simulate memory pressure (if specified alongside simulate argument) on the system till low memory notifications corresponding to are generated. Supported values are "warn" and "critical".

 -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.

DESCRIPTION
A tool to apply real or simulate memory pressure on the system

SEE ALSO
vm_stat(1)

关于xcode - 如何在 macOS 下模拟内存不足的情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54531898/

相关文章:

ios - 如何在选择行时通过更改 UIView 来制作 messageRead 指示器?

macos - OS X [NSTimer ScheduledTimerWithTimeInterval...] windowDidLoad 中的函数不起作用

macos - 如何在Mac Mountain Lion OS X v10.8上使用pip安装Scipy

ruby-on-rails - Docker 作为有效的 Rails 开发环境

cocoa - 如何在 XCode 4 中设置 QTKit 的文档类型?

cocoa - 如何为 App Store 签署应用程序,包括其框架的 .plist?

Cocoa:用户通知从未发送

xcode - 如何让 Xcode 记住我的私有(private) git 存储库密码?

ios - UITableView 中所有单元格的模糊效果背景

iphone - 如何在XCode控制台中按十六进制查找实例?