How much memory does an iOS app exceed before receiving a system memory warning?
In iOS applications, the triggering of system memory warnings is determined dynamically by the iOS operating system, and is not a fixed threshold. The system will determine whether to issue a memory warning based on the current available memory of the device, the memory requirements of other running applications, and the memory usage of the current application.
Memory warning triggers
Memory configuration of the device: Different devices have different amounts of memory, for example, an older device might have only 1GB of memory, while a newer device might have 4GB or more.
System memory pressure: If the system is under high memory pressure, memory warnings may be issued more frequently.
Memory usage of the application: If an app uses a lot of memory, the system will be more likely to issue a memory warning so that the app can release unnecessary memory.
Memory warning level
iOS provides three memory warning levels, developers can UIApplicationDelegate Through the realization ofapplicationDidReceiveMemoryWarning method to handle memory warnings.
Although iOS does not disclose specific memory warning trigger values, you can estimate them by observing the memory usage of different devices:
Low-end devices (such as iPhone 6 and 6s): Usually a memory warning may be triggered when the memory usage approaches 500MB.
Mid-range devices (like iPhone 7 and 8): A memory warning may be triggered when the memory usage approaches 1GB.
High-end devices (such as iPhone X and newer): A memory warning may be triggered when the memory usage exceeds 1.5GB.
How to respond to memory warnings
Release unnecessary resources: When receiving a memory warning, release memory that is no longer needed, such as cached images, temporary data, etc.
Delayed loading and lazy loading: Delay and lazy load resources whenever possible to reduce initial memory usage.
Optimizing data structures and algorithms: Select appropriate data structure and optimization algorithm to reduce memory usage.
Using Instruments: Regularly use the Instruments tool to detect and analyze memory usage to identify and resolve memory leaks and excessive memory usage issues.
By properly handling memory warnings and optimizing memory usage, you can significantly improve application performance and stability and reduce crashes and freezes caused by insufficient memory.
What is a reasonable amount of memory usage for iOS apps?
The reasonable memory usage of iOS applications depends on many factors, including the hardware configuration of the device, the functional complexity of the application, and the operating environment.
1. Device hardware configuration
Low-end devices: Devices with less memory (1GB or less) are sensitive to memory usage. Pay special attention to memory optimization.
Mid-range devices: For devices with medium memory (2GB to 3GB), the application can increase memory usage appropriately, but it still needs to be controlled within a reasonable range.
High-end equipment: On devices with larger memory (4GB and above), apps can use more memory, but excessive memory usage may still affect system performance.
2. Application type and function
Simple Application: For example, tool applications, news readers, etc., you should usually try to keep the memory usage below 100MB.
Medium complexity applications: For social media applications, lightweight games, etc., the memory usage should be controlled between 200MB and 500MB.
Complex Applications: For example, large games and graphic-intensive applications may use up to 500MB of memory or even higher, but try to avoid exceeding 1GB.
3. Memory usage monitoring
Use Xcode's Instruments tool to monitor the memory usage of your app, including the Allocations and Leaks templates. Ensure that the memory usage of your app is stable under normal use and that there are no obvious memory leaks.
4. Use appropriate memory usage metrics
4.1 Resident Memory
Resident memory is the physical memory actually occupied by the application, which can be monitored through the Allocations template of Instruments.
4.2 Virtual Memory
Virtual memory is the total memory accessible to applications, including swap memory. Virtual memory usage is usually higher than resident memory.
summary
Reasonable memory usage depends on the specific application type, functional complexity and target device. In general, you should try to keep the memory usage within a reasonable range and avoid exceeding the device's available memory limit. Through memory optimization practices, using appropriate data structures, optimizing image processing and code performance, etc., you can effectively reduce memory usage and improve application performance and stability. Use Instruments tools regularly to monitor and analyze memory usage to ensure that the application's memory usage is reasonable in various scenarios.