How To Simulate Memory Warning In Xcode 10 iOS Simulator

When you develop an iOS app, you sometimes need to simulate memory warning notifications to test your iOS app in high memory pressure conditions. Xcode simulator just provides such a tool for you to trigger memory warning notifications. Then you can test your source code in ViewController class’s didReceiveMemoryWarning function. This article will tell you how to do it.

1. Simulate Memory Warning Notification In Xcode iOS Simulator Steps.

  1. First, create an Xcode project.
  2. Then override and write some code in your ViewController class’s didReceiveMemoryWarning function like below. The class file name is ViewController.swift.
    override func didReceiveMemoryWarning() {
        print("view receive memory warning.")
  3. Now start an iOS simulator to run your Xcode iOS app project.
  4. When the iOS simulator startup, click it to focus on it, then click Debug —> Simulate Memory Warning menu item at the simulator top menu bar. This menu item will send the memory warning notification in the iOS simulator, and your app will receive the memory warning notification, and then run the code in ViewController class’s didReceiveMemoryWarning function.
  5. Now you can see the output text in Xcode debug console as below.
    view receive memory warning.
  6. If you do not know how to display the Xcode debug console and see the output text, please read the article How To Debug And Get Error Messages In Xcode Step By Step

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.