<!--
{
  "documentType" : "article",
  "framework" : "Xcode",
  "identifier" : "/documentation/Xcode/responding-to-low-memory-warnings",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Responding to low-memory warnings"
}
-->

# Responding to low-memory warnings

Detect when your app is using excessive memory, and bring memory use under control.

## Overview

iOS sends your app a warning when its memory use approaches the limit of available
device memory. The amount of memory use that triggers a memory warning corresponds
to the yellow region in Xcode’s memory gauge. Your app can receive a memory warning
in any of these ways:

- UIKit calls the <doc://com.apple.documentation/documentation/UIKit/UIApplicationDelegate/applicationDidReceiveMemoryWarning(_:)>
  method of your app delegate.
- UIKit calls the <doc://com.apple.documentation/documentation/UIKit/UIViewController/didReceiveMemoryWarning()>
  method of active <doc://com.apple.documentation/documentation/UIKit/UIViewController>
  objects.
- iOS posts <doc://com.apple.documentation/documentation/UIKit/UIApplication/didReceiveMemoryWarningNotification>
  to the default notification center.
- Dispatch queues receive an event with source type <doc://com.apple.documentation/documentation/Dispatch/DISPATCH_SOURCE_TYPE_MEMORYPRESSURE>.

The operating system sends low-memory warnings using a best-effort approach, and
your app needs to respond to them as quickly as possible. If memory demand on the
system increases faster than the warnings relieve memory pressure, the system may
not have time to send the low-memory warnings and wait for apps to respond. When
this occurs, the system resorts to jettisoning apps to reclaim their memory and recording
the reason in a log file, as described in [Identifying high-memory use with jetsam event reports](/documentation/Xcode/identifying-high-memory-use-with-jetsam-event-reports).

Make sure your app changes its approach for allocating memory when it receives a
memory warning—adopting a conservative policy of looking for opportunities to release
objects or reduce their size as it uses them. If your app allocates large amounts
of memory at once and crashes before it receives the low-memory warning during the
large allocation, modify your code to slowly allocate the necessary memory, so the
system has adequate time to free memory from across the system.

If your app loads data it can easily recreate, consider using <doc://com.apple.documentation/documentation/Foundation/NSPurgeableData>.
When the contents of <doc://com.apple.documentation/documentation/Foundation/NSPurgeableData>
aren’t marked as in-use through <doc://com.apple.documentation/documentation/Foundation/NSDiscardableContent/beginContentAccess()>,
the system automatically discards the contents in low-memory situations. This automatic
discard process helps your app react to a low-memory warnings more quickly, because
the kernel handles discarding the data, rather than your app, which is waiting to
receive the low-memory notification before discarding the data.

> Important: Don’t traverse your app’s whole object graph looking for memory to release
> when your app receives a memory warning, and avoid using <doc://com.apple.documentation/documentation/Foundation/NSCache>
> in connection with <doc://com.apple.documentation/documentation/Foundation/NSPurgeableData>.
> iOS compresses memory pages that apps haven’t accessed recently. Searching for memory
> to purge brings these pages out of the compressor, and increases memory demands on
> the system.

## See Also

[Identifying high-memory use with jetsam event reports](/documentation/Xcode/identifying-high-memory-use-with-jetsam-event-reports)

Discover why the operating system terminated your app when available memory was low.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)