ios memory deep dive - devstreaming-cdn.apple.com · memory footprint pages typically 16kb page...
TRANSCRIPT
![Page 1: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/1.jpg)
#WWDC18
© 2018 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.
Kyle Howarth, Software Engineer James Snee, Software Engineer Kris Markel, Software Engineer
•iOS Memory Deep Dive • Session 416
![Page 2: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/2.jpg)
•Why reduce memory •Memory footprint •Tools for profiling footprint •Images •Optimizing when in background •Demo
![Page 3: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/3.jpg)
•Why Reduce Memory
![Page 4: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/4.jpg)
Users have a better experience.
![Page 5: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/5.jpg)
•Memory Footprint •Not all memory is created equal
![Page 6: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/6.jpg)
Memory Footprint Pages
![Page 7: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/7.jpg)
Memory Footprint Pages
![Page 8: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/8.jpg)
Memory Footprint Pages
UIView
UILabelString
![Page 9: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/9.jpg)
Memory Footprint Pages
UIView
UILabelString
Data
![Page 10: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/10.jpg)
Memory Footprint Pages
Typically 16KB
Page types • Clean • Dirty
![Page 11: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/11.jpg)
Memory Footprint Pages
Typically 16KB
Page types • Clean • Dirty
xNumber of pages
Page size = Memory in use
![Page 12: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/12.jpg)
Memory Footprint Clean and dirty pages
int *array = malloc(20000 * sizeof(int)); array[0] = 32 array[19999] = 64
![Page 13: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/13.jpg)
Memory Footprint Clean and dirty pages
int *array = malloc(20000 * sizeof(int)); array[0] = 32 array[19999] = 64
![Page 14: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/14.jpg)
Memory Footprint Clean and dirty pages
int *array = malloc(20000 * sizeof(int)); array[0] = 32 array[19999] = 64
![Page 15: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/15.jpg)
Memory Footprint Clean and dirty pages
int *array = malloc(20000 * sizeof(int)); array[0] = 32 array[19999] = 64
![Page 16: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/16.jpg)
Memory Footprint Clean and dirty pages
32
int *array = malloc(20000 * sizeof(int)); array[0] = 32 array[19999] = 64
![Page 17: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/17.jpg)
32
Memory Footprint Clean and dirty pages
64
int *array = malloc(20000 * sizeof(int)); array[0] = 32 array[19999] = 64
![Page 18: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/18.jpg)
Memory Footprint Memory mapped files
File-backed memory
Read-only files are clean
Kernel manages when file is in RAM
![Page 19: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/19.jpg)
Memory Footprint Memory mapped files
50KB
![Page 20: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/20.jpg)
Memory Footprint Memory mapped files
50KB
![Page 21: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/21.jpg)
Memory Footprint Typical app memory profile
Clean
Dirty
Compressed
![Page 22: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/22.jpg)
Memory Footprint Clean memory
Data that can be paged out of memory
![Page 23: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/23.jpg)
Memory Footprint Clean memory
CleanMemory
Data that can be paged out of memory
![Page 24: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/24.jpg)
CleanMemory
Memory Footprint Clean memory
Data that can be paged out of memory
Memory mapped files
![Page 25: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/25.jpg)
CleanMemory
Image.jpg
Training.model
Blob.data
Memory Footprint Clean memory
Data that can be paged out of memory
Memory mapped files
![Page 26: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/26.jpg)
CleanMemory
Memory Footprint Clean memory
Data that can be paged out of memory
Memory mapped files
Frameworks* __DATA_CONST
UIKit
__DATA_CONST
CoreGraphics
![Page 27: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/27.jpg)
Memory Footprint Dirty memory
![Page 28: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/28.jpg)
Memory Footprint Dirty memory
Dirty Memory
![Page 29: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/29.jpg)
Memory Footprint Dirty memory
Memory written by an app
Dirty Memory
![Page 30: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/30.jpg)
Dirty Memory
Memory Footprint Dirty memory
Memory written by an app
All heap allocations
String
UIViews
NSCache
Array
malloc
![Page 31: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/31.jpg)
Dirty Memory
Memory Footprint Dirty memory
Memory written by an app
All heap allocations
Decoded image buffersCGRasterData
ImageIO
![Page 32: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/32.jpg)
Dirty Memory
Memory Footprint Dirty memory
Memory written by an app
All heap allocations
Decoded image buffers
Frameworks
__DATA __DATA_DIRTY
__DATA __DATA_DIRTY
UIKit
CoreGraphics
![Page 33: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/33.jpg)
Memory Footprint Frameworks
Frameworks contribute to dirty memory
Singletons
Global initializers
+(void)load; // Objective-C +(void)initialize; // Objective-C __attribute__((constructor)) // Objective-C
initialize(); // Swift
![Page 34: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/34.jpg)
Memory Footprint Compressed memory
No traditional disk swap
Memory compressor • Compresses unaccessed pages • Decompresses pages upon access
![Page 35: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/35.jpg)
Memory Footprint Compressed memory
No traditional disk swap
Memory compressor • Compresses unaccessed pages • Decompresses pages upon access
NSDataNSDataDictionary
![Page 36: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/36.jpg)
NSDataNSDataDictionary
No traditional disk swap
Memory compressor • Compresses unaccessed pages • Decompresses pages upon access
Memory Footprint Compressed memory
• Compresses stale pages
![Page 37: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/37.jpg)
App is not always the cause
Compressor complicates freeing memory
Prefer policy changes over cache purging
Memory Footprint Memory warnings
![Page 38: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/38.jpg)
override func didReceiveMemoryWarning() { cache.removeAllObjects() super.didReceiveMemoryWarning() }
Memory Footprint Memory warnings
![Page 39: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/39.jpg)
override func didReceiveMemoryWarning() { cache.removeAllObjects() super.didReceiveMemoryWarning() }
Memory Footprint Memory warnings
![Page 40: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/40.jpg)
override func didReceiveMemoryWarning() { cache.removeAllObjects() super.didReceiveMemoryWarning() }
Memory Footprint Memory warnings
NSDataNSDataDictionary
![Page 41: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/41.jpg)
override func didReceiveMemoryWarning() { cache.removeAllObjects() super.didReceiveMemoryWarning() }
Memory Footprint Memory warnings
NSDataNSDataDictionary
![Page 42: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/42.jpg)
override func didReceiveMemoryWarning() { cache.removeAllObjects() super.didReceiveMemoryWarning() }
Memory Footprint Memory warnings
NSDataNSDataDictionary
![Page 43: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/43.jpg)
Memory Footprint Caching
Trade-offs between CPU and memory
Remember the compressor
Prefer NSCache over dictionary
![Page 44: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/44.jpg)
Memory Footprint Typical app memory profile
Clean
Dirty
Compressed
![Page 45: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/45.jpg)
Memory Footprint Typical app memory profile
Clean
Dirty
Compressed
![Page 46: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/46.jpg)
Memory Footprint Typical app memory profile
Clean
Dirty
Compressed
Footprint
![Page 47: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/47.jpg)
Memory Footprint Typical app memory profile
Clean
Dirty
Compressed
Footprint limits Footprint
![Page 48: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/48.jpg)
Memory Footprint Typical app memory profile
Clean
Dirty
Compressed
Footprint limits• Limits vary by device
Footprint
![Page 49: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/49.jpg)
Memory Footprint Typical app memory profile
Clean
Dirty
Compressed
Footprint limits• Limits vary by device• Apps have a fairly high footprint limit
Footprint
![Page 50: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/50.jpg)
Memory Footprint Typical app memory profile
Clean
Dirty
Compressed
Footprint limits• Limits vary by device• Apps have a fairly high footprint limit• Extensions have a much lower limit
Footprint
![Page 51: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/51.jpg)
Memory Footprint Typical app memory profile
Clean
Dirty
Compressed
Footprint limits• Limits vary by device• Apps have a fairly high footprint limit• Extensions have a much lower limit
Exception upon exceeding limit
Footprint
![Page 52: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/52.jpg)
Memory Footprint Typical app memory profile
Clean
Dirty
Compressed
Footprint limits• Limits vary by device• Apps have a fairly high footprint limit• Extensions have a much lower limit
Exception upon exceeding limit•EXC_RESOURCE_EXCEPTION
Footprint
![Page 53: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/53.jpg)
James Snee, Apple/Software Engineer
•Tools for Profiling Footprint
![Page 54: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/54.jpg)
Tools for Profiling Footprint Xcode memory gauge
![Page 55: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/55.jpg)
Tools for Profiling Footprint Xcode memory gauge
![Page 56: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/56.jpg)
Tools for Profiling Footprint Xcode memory gauge
![Page 57: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/57.jpg)
Tools for Profiling Footprint Instruments
![Page 58: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/58.jpg)
Tools for Profiling Footprint Instruments
Allocations
Leaks
VM Tracker
Virtual memory trace
![Page 59: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/59.jpg)
Tools for Profiling Footprint Instruments — VM Tracker
![Page 60: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/60.jpg)
Tools for Profiling Footprint Instruments — VM Tracker
![Page 61: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/61.jpg)
Tools for Profiling Footprint Instruments — VM Tracker
![Page 62: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/62.jpg)
Tools for Profiling Footprint Instruments — Virtual Memory Trace
![Page 63: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/63.jpg)
Tools for Profiling Footprint Instruments — Virtual Memory Trace
![Page 64: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/64.jpg)
Tools for Profiling Footprint Instruments — Virtual Memory Trace
![Page 65: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/65.jpg)
Tools for Profiling Footprint Xcode Debugger — memory resource exceptions NEW
![Page 66: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/66.jpg)
Tools for Profiling Footprint Xcode Debugger — memory resource exceptions NEW
![Page 67: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/67.jpg)
Tools for Profiling Footprint Xcode Debugger — memory resource exceptions NEW
![Page 68: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/68.jpg)
Tools for Profiling Footprint Xcode Memory Debugger
![Page 69: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/69.jpg)
Tools for Profiling Footprint Xcode Memory Debugger
![Page 70: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/70.jpg)
Tools for Profiling Footprint Xcode Memory Debugger
![Page 71: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/71.jpg)
Tools for Profiling Footprint Xcode Memory Debugger
![Page 72: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/72.jpg)
Tools for Profiling Footprint vmmap NEW
Shows virtual memory regions allocated in a process
vmmap App.memgraph vmmap --summary App.memgraph
![Page 73: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/73.jpg)
Tools for Profiling Footprint vmmap --summary App.memgraph
![Page 74: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/74.jpg)
Tools for Profiling Footprint vmmap --summary App.memgraph
![Page 75: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/75.jpg)
Tools for Profiling Footprint vmmap --summary App.memgraph
![Page 76: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/76.jpg)
Tools for Profiling Footprint vmmap --summary App.memgraph
![Page 77: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/77.jpg)
Zoom and focusTools for Profiling Footprint vmmap App.memgraph
![Page 78: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/78.jpg)
Zoom and focusTools for Profiling Footprint vmmap App.memgraph
![Page 79: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/79.jpg)
Tools for Profiling Footprint vmmap App.memgraph
![Page 80: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/80.jpg)
Tools for Profiling Footprint vmmap App.memgraph
![Page 81: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/81.jpg)
Tools for Profiling Footprint vmmap and AWK
![Page 82: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/82.jpg)
Tools for Profiling Footprint vmmap and AWK
![Page 83: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/83.jpg)
Tools for Profiling Footprint vmmap and AWK
![Page 84: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/84.jpg)
Tools for Profiling Footprint vmmap and AWK
![Page 85: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/85.jpg)
Tools for Profiling Footprint vmmap and AWK
![Page 86: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/86.jpg)
Tools for Profiling Footprint vmmap and AWK
![Page 87: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/87.jpg)
Tools for Profiling Footprint leaks NEW
Shows objects that are allocated, but no longer referenced
leaks App.memgraph
![Page 88: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/88.jpg)
Tools for Profiling Footprint leaks
![Page 89: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/89.jpg)
Tools for Profiling Footprint leaks
![Page 90: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/90.jpg)
Tools for Profiling Footprint leaks MyApp.memgraph NEW
![Page 91: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/91.jpg)
Tools for Profiling Footprint leaks MyApp.memgraph NEW
![Page 92: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/92.jpg)
Tools for Profiling Footprint leaks MyApp.memgraph NEW
![Page 93: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/93.jpg)
Tools for Profiling Footprint leaks MyApp.memgraph NEW
![Page 94: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/94.jpg)
Tools for Profiling Footprint heap NEW
Shows objects allocated on the heap
Useful for identifying large objects in memory and what allocated it
heap App.memgraph heap App.memgraph -sortBySize heap App.memgraph -addresses all | <classes-pattern>
![Page 95: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/95.jpg)
Tools for Profiling Footprint heap App.memgraph
![Page 96: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/96.jpg)
Tools for Profiling Footprint heap App.memgraph
![Page 97: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/97.jpg)
Tools for Profiling Footprint heap App.memgraph
![Page 98: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/98.jpg)
Tools for Profiling Footprint heap App.memgraph
![Page 99: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/99.jpg)
Tools for Profiling Footprint heap App.memgraph
![Page 100: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/100.jpg)
Tools for Profiling Footprint heap --sortBySize App.memgraph
![Page 101: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/101.jpg)
Tools for Profiling Footprint heap --sortBySize App.memgraph
![Page 102: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/102.jpg)
Tools for Profiling Footprint heap App.memgraph -addresses all | <classes-pattern>
![Page 103: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/103.jpg)
Tools for Profiling Footprint heap App.memgraph -addresses all | <classes-pattern>
![Page 104: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/104.jpg)
Tools for Profiling Footprint Enabling malloc stack logging
![Page 105: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/105.jpg)
Tools for Profiling Footprint Enabling malloc stack logging
![Page 106: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/106.jpg)
Tools for Profiling Footprint malloc_history NEW
Shows backtraces for malloc and anonymous VM region allocations
malloc_history App.memgraph [address]
![Page 107: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/107.jpg)
Tools for Profiling Footprint malloc_history <memgraph> <address>
![Page 108: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/108.jpg)
Tools for Profiling Footprint malloc_history <memgraph> <address>
![Page 109: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/109.jpg)
Tools for Profiling Footprint Which tool to pick?
![Page 110: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/110.jpg)
Tools for Profiling Footprint Which tool to pick?
Creation Reference Size
![Page 111: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/111.jpg)
Tools for Profiling Footprint Which tool to pick?
Creation Reference Size
malloc_history
![Page 112: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/112.jpg)
Tools for Profiling Footprint Which tool to pick?
Creation Reference Size
malloc_history leaks
![Page 113: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/113.jpg)
Tools for Profiling Footprint Which tool to pick?
Creation Reference Size
malloc_history leaks vmmap, heap
![Page 114: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/114.jpg)
Kyle Howarth, Apple/Software Engineer
•Images
![Page 115: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/115.jpg)
Memory use is related to the dimensions of the image, not the file size.
![Page 116: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/116.jpg)
Images
590Kb file size
![Page 117: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/117.jpg)
Images
590KB file size
![Page 118: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/118.jpg)
Images
590KB file size
1536px
2048px
![Page 119: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/119.jpg)
2048 pixels x 1536 pixels x 4 bytes per pixel
10MB
![Page 120: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/120.jpg)
Images
Load RenderDecode
![Page 121: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/121.jpg)
Images
Load
590Kb
![Page 122: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/122.jpg)
Images
Load
590KB
Decode
10MB
![Page 123: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/123.jpg)
Images
Load RenderDecode
590KB 10MB
Images and Graphics Best Practices WWWDC 2018
![Page 124: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/124.jpg)
Images Image-rendering formats
SRGB Format • Four bytes per pixel • Full color images
![Page 125: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/125.jpg)
Images Image-rendering formats
Wide format • Eight bytes per pixel • Super accurate colors • Only useful with wide color displays • Wide color capture cameras - iPhone 7, iPhone 8, iPhone X, iPad Pro 10.5”,
iPad Pro 13” (2nd generation)
![Page 126: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/126.jpg)
Images Image rendering formats
Luminance and alpha 8 format • Two bytes per pixel • Single-color images and alpha • Metal shaders
![Page 127: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/127.jpg)
Images Image rendering formats
Alpha 8 Format • One byte per pixel • Useful for monochrome images - Masks - Emoji-free text
• 75 percent smaller than SRGB
![Page 128: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/128.jpg)
Images Image rendering formats
Optimized formats reduce memory use • One byte: Alpha 8 • Two bytes: luminance and alpha 8 • Four bytes: SRGB • Eight bytes: wide format
![Page 129: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/129.jpg)
How do I pick the right format?
![Page 130: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/130.jpg)
Don’t pick the format, let the format pick you
Stop using UIGraphicsBeginImageContextWithOptions • Four bytes per pixel format
Start or keep using UIGraphicsImageRenderer • Introduced in iOS 10 • Automatically picks best graphics format in iOS 12
Images Picking the right format
![Page 131: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/131.jpg)
// Circle via UIGraphicsImageContext
let bounds = CGRect(x: 0, y: 0, width:300, height: 100) UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0)
// Drawing Code UIColor.black.setFill() let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize(width: 20, height: 20)) path.addClip() UIRectFill(bounds)
let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext()
![Page 132: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/132.jpg)
// Circle via UIGraphicsImageContext
let bounds = CGRect(x: 0, y: 0, width:300, height: 100) UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0)
// Drawing Code UIColor.black.setFill() let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize(width: 20, height: 20)) path.addClip() UIRectFill(bounds)
let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext()
![Page 133: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/133.jpg)
// Circle via UIGraphicsImageRenderer
let bounds = CGRect(x: 0, y: 0, width:300, height: 100) let renderer = UIGraphicsImageRenderer(size: bounds.size) let image = renderer.image { context in // Drawing Code UIColor.black.setFill() let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize(width: 20, height: 20)) path.addClip() UIRectFill(bounds) }
![Page 134: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/134.jpg)
// Circle via UIGraphicsImageRenderer
let bounds = CGRect(x: 0, y: 0, width:300, height: 100) let renderer = UIGraphicsImageRenderer(size: bounds.size) let image = renderer.image { context in // Drawing Code UIColor.black.setFill() let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize(width: 20, height: 20)) path.addClip() UIRectFill(bounds) }
![Page 135: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/135.jpg)
// Circle via UIGraphicsImageRenderer
let bounds = CGRect(x: 0, y: 0, width:300, height: 100) let renderer = UIGraphicsImageRenderer(size: bounds.size) let image = renderer.image { context in // Drawing Code UIColor.black.setFill() let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize(width: 20, height: 20)) path.addClip() UIRectFill(bounds) }
// Make circle render blue, but stay at 1 byte-per-pixel image let imageView = UIImageView(image: image) imageView.tintColor = .bluelet imageView = UIImageView(image: image) imageView.tintColor = .blue
![Page 136: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/136.jpg)
// Circle via UIGraphicsImageRenderer
let bounds = CGRect(x: 0, y: 0, width:300, height: 100) let renderer = UIGraphicsImageRenderer(size: bounds.size) let image = renderer.image { context in // Drawing Code UIColor.black.setFill() let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize(width: 20, height: 20)) path.addClip() UIRectFill(bounds) }
// Make circle render blue, but stay at 1 byte-per-pixel image let imageView = UIImageView(image: image) imageView.tintColor = .bluelet imageView = UIImageView(image: image) imageView.tintColor = .blue
![Page 137: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/137.jpg)
// Circle via UIGraphicsImageRenderer
let bounds = CGRect(x: 0, y: 0, width:300, height: 100) let renderer = UIGraphicsImageRenderer(size: bounds.size) let image = renderer.image { context in // Drawing Code UIColor.black.setFill() let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize(width: 20, height: 20)) path.addClip() UIRectFill(bounds) }
// Make circle render blue, but stay at 1 byte-per-pixel image let imageView = UIImageView(image: image) imageView.tintColor = .bluelet imageView = UIImageView(image: image) imageView.tintColor = .blue
![Page 138: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/138.jpg)
Images Downsampling
UIImage is expensive for sizing and to resizing • Will decompress original image into memory • Internal coordinate space transforms are expensive
ImageIO can read image sizes and metadata information without dirtying memory
ImageIO can resize images at cost of resized image only
![Page 139: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/139.jpg)
// Image size with UIImage
import UIKit
// Getting image size let filePath = “/path/to/image.jpg” let image = UIImage(contentsOfFile: filePath) let imageSize = image.size
// Resizing image let scale = 0.2 let size = CGSize(image.size.width * scale, image.size.height * scale) let renderer = UIGraphicsImageRenderer(size: size) let resizedImage = renderer.image { context in image.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height)) }
![Page 140: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/140.jpg)
// Image size with UIImage
import UIKit
// Getting image size let filePath = “/path/to/image.jpg” let image = UIImage(contentsOfFile: filePath) let imageSize = image.size
// Resizing image let scale = 0.2 let size = CGSize(image.size.width * scale, image.size.height * scale) let renderer = UIGraphicsImageRenderer(size: size) let resizedImage = renderer.image { context in image.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height)) }
![Page 141: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/141.jpg)
// Image size with UIImage
import UIKit
// Getting image size let filePath = “/path/to/image.jpg” let image = UIImage(contentsOfFile: filePath) let imageSize = image.size
// Resizing image let scale = 0.2 let size = CGSize(image.size.width * scale, image.size.height * scale) let renderer = UIGraphicsImageRenderer(size: size) let resizedImage = renderer.image { context in image.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height)) }
![Page 142: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/142.jpg)
// Image size with ImageIO
import ImageIO
let filePath = “/path/to/image.jpg” let url = NSURL(fileURLWithPath: path)
let imageSource = CGImageSourceCreateWithURL(url, nil) let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) let options: [NSString: Any] = [ kCGImageSourceThumbnailMaxPixelSize: 100, kCGImageSourceCreateThumbnailFromImageAlways: true ]
let scaledImage = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options)
![Page 143: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/143.jpg)
// Image size with ImageIO
import ImageIO
let filePath = “/path/to/image.jpg” let url = NSURL(fileURLWithPath: path)
let imageSource = CGImageSourceCreateWithURL(url, nil) let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) let options: [NSString: Any] = [ kCGImageSourceThumbnailMaxPixelSize: 100, kCGImageSourceCreateThumbnailFromImageAlways: true ]
let scaledImage = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options)
![Page 144: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/144.jpg)
// Image size with ImageIO
import ImageIO
let filePath = “/path/to/image.jpg” let url = NSURL(fileURLWithPath: path)
let imageSource = CGImageSourceCreateWithURL(url, nil) let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) let options: [NSString: Any] = [ kCGImageSourceThumbnailMaxPixelSize: 100, kCGImageSourceCreateThumbnailFromImageAlways: true ]
let scaledImage = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options)
![Page 145: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/145.jpg)
// Image size with ImageIO
import ImageIO
let filePath = “/path/to/image.jpg” let url = NSURL(fileURLWithPath: path)
let imageSource = CGImageSourceCreateWithURL(url, nil) let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) let options: [NSString: Any] = [ kCGImageSourceThumbnailMaxPixelSize: 100, kCGImageSourceCreateThumbnailFromImageAlways: true ]
let scaledImage = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options)
![Page 146: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/146.jpg)
•Optimizing when in the background
![Page 147: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/147.jpg)
![Page 148: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/148.jpg)
![Page 149: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/149.jpg)
Unload large resources you cannot see.
![Page 150: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/150.jpg)
App lifecycle • Listen for UIApplicationWillEnterForeground and UIApplicationDidEnterBackground notifications
• Applies to on-screen views
UIViewController appearance cycle • Leverage viewWillAppear and viewDidDisappear • Off-screen view controllers in UITabBarController and UINavigationController
Optimizing When in the Background Unloading when off-screen
![Page 151: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/151.jpg)
// Unloading resources on foreground/background
NotificationCenter.default.addObserver(forName: .UIApplicationDidEnterBackground, object: nil, queue: .main) { [weak self] (note) in // Unload large resources when off-screen self.unloadImages() }
NotificationCenter.default.addObserver(forName: .UIApplicationWillEnterForeground, object: nil, queue:.main) { [weak self] (note) in // Load large resources when off-screen self.loadImages() }
![Page 152: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/152.jpg)
// Unloading resources on foreground/background
NotificationCenter.default.addObserver(forName: .UIApplicationDidEnterBackground, object: nil, queue: .main) { [weak self] (note) in // Unload large resources when off-screen self.unloadImages() }
NotificationCenter.default.addObserver(forName: .UIApplicationWillEnterForeground, object: nil, queue:.main) { [weak self] (note) in // Load large resources when off-screen self.loadImages() }
![Page 153: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/153.jpg)
// Unloading resources on foreground/background
NotificationCenter.default.addObserver(forName: .UIApplicationDidEnterBackground, object: nil, queue: .main) { [weak self] (note) in // Unload large resources when off-screen self.unloadImages() }
NotificationCenter.default.addObserver(forName: .UIApplicationWillEnterForeground, object: nil, queue:.main) { [weak self] (note) in // Load large resources when off-screen self.loadImages() }
![Page 154: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/154.jpg)
// Unloading resources on foreground/background
// Unload large resource when off-screen override func viewDidDisappear(_ animated: Bool) { unloadImages() super.viewDidDisappear(animated) }
// Load large resources when on-screen override func viewWillAppear(_ animated: Bool) { loadImages() super.viewWillAppear(animated) }
![Page 155: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/155.jpg)
// Unloading resources on foreground/background
// Unload large resource when off-screen override func viewDidDisappear(_ animated: Bool) { unloadImages() super.viewDidDisappear(animated) }
// Load large resources when on-screen override func viewWillAppear(_ animated: Bool) { loadImages() super.viewWillAppear(animated) }
![Page 156: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/156.jpg)
// Unloading resources on foreground/background
// Unload large resource when off-screen override func viewDidDisappear(_ animated: Bool) { unloadImages() super.viewDidDisappear(animated) }
// Load large resources when on-screen override func viewWillAppear(_ animated: Bool) { loadImages() super.viewWillAppear(animated) }
![Page 157: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/157.jpg)
Kris Markel, Apple/Software Engineer
•Demo
![Page 158: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/158.jpg)
Summary
![Page 159: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/159.jpg)
Memory is a finite and shared resource
Summary
![Page 160: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/160.jpg)
Memory is a finite and shared resource
Monitor memory use when running from Xcode
Summary
![Page 161: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/161.jpg)
Memory is a finite and shared resource
Monitor memory use when running from Xcode
Let iOS pick your image formats
Summary
![Page 162: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/162.jpg)
Memory is a finite and shared resource
Monitor memory use when running from Xcode
Let iOS pick your image formats
Use ImageIO for downsampling images
Summary
![Page 163: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/163.jpg)
Memory is a finite and shared resource
Monitor memory use when running from Xcode
Let iOS pick your image formats
Use ImageIO for downsampling images
Unload large resources that are off-screen
Summary
![Page 164: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/164.jpg)
Memory is a finite and shared resource
Monitor memory use when running from Xcode
Let iOS pick your image formats
Use ImageIO for downsampling images
Unload large resources that are off-screen
Use memory graphs to further understand and reduce memory footprint
Summary
![Page 165: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/165.jpg)
Memory is a finite and shared resource
Monitor memory use when running from Xcode
Let iOS pick your image formats
Use ImageIO for downsampling images
Unload large resources that are off-screen
Use memory graphs to further understand and reduce memory footprint
Summary
![Page 166: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/166.jpg)
More Informationhttps://developer.apple.com/wwdc18/416
![Page 167: iOS Memory Deep Dive - devstreaming-cdn.apple.com · Memory Footprint Pages Typically 16KB Page types • Clean • Dirty Number x of pages Page size = Memory in use](https://reader030.vdocuments.mx/reader030/viewer/2022011920/601d09ace029de2dbf6c757a/html5/thumbnails/167.jpg)