21.9 · Memory you can count: allocations, dirty versus clean pages and decoded images
Memory problems are about how much is resident and dirty and how many allocations you make, not how large your files are. Both can be counted.
Mental model. Count heap blocks, separate dirty from clean pages, and size a bitmap from its pixels, not its file.
Resident memory
What the memory limit actually counts, and what an image costs when decoded.
- What counts toward an app’s memory limit: why is reserved memory free, a mapped file cheap, and the same file read into a buffer expensive?
The limit that gets an app killed is about dirty memory (plus compressed memory), what the system cannot simply discard or reload from disk (Q162). In the… - A 2 MB JPEG costs how much memory once it is shown, and what does downsampling at decode time change?
A compressed file's size says nothing about its memory cost. A decoded bitmap needs width × height × bytes per pixel (4 for 8-bit RGBA), and the row stride may…
More in Performance & energy
- 21.1 · Measure first: the method, the metrics and the noise
- 21.2 · Instruments templates, signposts and XCTMetric
- 21.3 · MetricKit, Organizer and a performance culture
- 21.4 · SwiftUI invalidation and long lists
- 21.5 · The costs that show up in profiles: collections, strings, formatters, JSON, images and disk
- 21.6 · Energy: CPU wake-ups, timers, radios, location and thermal state
- 21.7 · App size: thinning, on-demand resources and the binary
- 21.8 · Writing benchmarks you can believe: the optimiser, build settings and growth tests
- 21.10 · The main thread in code: hang watchdogs, actor hops and quality of service
- 21.11 · Launch: lazy initialisation and measuring from process start
- 21.12 · Counting wake-ups: why polling costs energy even when the work is tiny