Skip to content

Instantly share code, notes, and snippets.

@sunbohong
Created October 9, 2019 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunbohong/2c05c953d20e2a3987d43bbc4ff0605d to your computer and use it in GitHub Desktop.
Save sunbohong/2c05c953d20e2a3987d43bbc4ff0605d to your computer and use it in GitHub Desktop.
Monitor memory warning
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE,
0,
0x1|0x2|0x4|0x8|0x10|0x20|0xf0000000,
NULL);
dispatch_source_set_event_handler(source, ^{
dispatch_source_memorypressure_flags_t pressureLevel = dispatch_source_get_data(source);
NSLog(@"Received memory warning with pressure: %@", @(pressureLevel).description);
});
dispatch_resume(source);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment