From the course: iOS Development: Architecture
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Dispatch source memory pressure
From the course: iOS Development: Architecture
Dispatch source memory pressure
- [Instructor] We can also use dispatch sources to intercept memory pressure events. This is a more advanced technique of monitoring the system for low memory issues. It even lets us distinguish the severity of the memory pressure. We're going to implement the utility class to demonstrate the power of this approach. So, lets add a new file. I call it, MemoryPressureMonitor. I create a class and make the singleton by defining the shared type instance. The initializer needs to be private to guarantee the singleton behavior. We need a DispatchSource of type dispatch source memory pressure. The DispatchSource class exposes several type methods to create different dispatch sources. To create a DispatchSource memory pressure instance, we use the makeMemoryPressureSource eventMask type method. The method takes on eventMask's argument. We want to be notified about warning and critical level memory pressure events. So, I will provide these two values, warning and critical. Next, in the private…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.