skip to content

On a 3 GB phone, how would you budget memory for a photo-editing session with layered edits and a 30-step undo history on a 48-megapixel photo?

level: seniorimportance: should knowfreq 48%

answer

  1. pixels, not file size
  2. width x height x four bytes
  3. count every layer and preview
  4. undo keeps operations, not bitmaps
  5. tiles flatten the export peak

basics

~10 s

Count decoded pixels: a 48-megapixel image at four bytes a pixel is about 192 MB. Hold one full-resolution buffer at most, layers as parameters, screen-sized previews, a tiled export, and undo as operations.

solid answer

~50 s

Decoded memory is width x height x bytes per pixel, whatever the file's compressed size: 48 million pixels x 4 bytes is about **192 MB**. A naive editor holding the original, a bitmap per layer, an output buffer and a snapshot per undo step needs 30 x 192 MB, about **5.8 GB**, for undo alone. The OS, not the phone's 3 GB, sets the ceiling, and it publishes no number, so assume one — say 500 MB for this device class — and measure it. The budgeted design keeps one full-resolution source (192 MB) at most; layers as filter parameters plus masks stored as strokes or at reduced resolution; two screen-sized previews of about 10 MB each; an export rendered in tiles of about 1 MB; and **undo as an operation list** with occasional checkpoints on disk. That lands near 330 MB with the rest of the app, leaving headroom for the export peak.

go deeper

for a junior

Recall that decoded images cost width times height times four bytes, so a 48-megapixel photo is about 192 MB no matter how small its file.

for a middle

Explain the budget line by line: one source, parameter layers, screen-sized previews, tiled output, and why undo stores operations instead of bitmaps.

for a senior

Show that the ceiling is an assumption you measure per device class, that you budget for the export peak, and that undo checkpoints trade replay time against memory.

for a principal

Discuss how a memory budget is split between features owned by different teams, and who must give back memory when a new feature needs it.

## Decoded pixels, not file size A photo file is compressed; the pixels the app edits are not. Once decoded, an image occupies **width x height x bytes per pixel**, and full colour with transparency takes **four bytes per pixel**. One platform's guide gives the scale: a 2048 x 1536 image costs about 12 MB decoded, while a 512 x 384 version costs 0.75 MB. A 48-megapixel photo — for example 8000 x 6000 — is 48 million pixels x 4 bytes, about **192 MB**, however small its file. Every decoded copy, layer, preview and GPU texture of it is counted the same way. On phones the GPU typically uses the same RAM as the CPU (one platform's memory guide says so explicitly), so a texture of the full image is another 192 MB, not free graphics memory. ## The naive session | Item | Naive design | Budgeted design | |---|---|---| | Source image | 192 MB decoded | 192 MB, or tiles read on demand | | Three adjustment layers | 3 x 192 MB = 576 MB | parameters (bytes) + masks about 3 MB each | | Output buffer | 192 MB | rendered in tiles, about 4 MB in flight | | Previews | one full-size copy | two screen-sized, about 10 MB each | | Undo, 30 steps | 30 x 192 MB, about 5.8 GB | operation list (kilobytes) + checkpoints on disk | | Rest of the app (assumed) | 100 MB | 100 MB | | **Total** | about 7 GB | about 330 MB | The naive column cannot run on any phone. The budgeted one fits under the assumed ceiling with room for the peak. ## Where the ceiling comes from The phone's 3 GB is shared with the OS, its services and every other app. The OS decides how much one app may hold, and it does not publish the figure: one platform's documentation says the limit that ends an app depends on the device, and the other ranks processes by importance and kills the most memory-intensive when memory runs short. So the budget is an **assumption to measure**: - run the editing session on the lowest-memory phone you support and find where the app is ended; - read field reports of peak memory and of how often the app was ended for memory, by device class; - set the budget below that line with headroom, and scale it with the device's total RAM where the platform reports it. For this answer, assume about **500 MB** on a 3 GB phone. The design must not depend on the exact figure. ## The budgeted design - **One full-resolution source at most.** Or none: very large originals can be read region by region, the way a zoomable viewer reads tiles. - **Layers as parameters.** An exposure or colour layer is a few numbers. A painted mask is a list of brush strokes, rasterised when needed, or a one-byte-per-pixel mask at reduced resolution — 2000 x 1500 at one byte is 3 MB. - **Screen-sized previews.** A 2400 x 1080 screen holds about 2.6 million pixels, about 10 MB at four bytes. Two cover the current and the in-progress preview. - **Tiled export.** Rendering 512 x 512 tiles (1 MB each) keeps only a few in flight, so export never needs a second full-size output buffer. ## Undo as operations 1. Each committed edit appends a small record — the operation and its parameters, or the strokes of a brush — to an in-memory list mirrored to disk. 2. Every N steps, write a checkpoint image to disk, not to memory. 3. Undo replays the operations from the nearest checkpoint, or from the original. 4. A pixel-level edit that cannot be replayed cheaply stores only the changed tiles as a diff, not the whole bitmap. Thirty steps of operations cost kilobytes. The trade is time: undoing far back replays more work, which checkpoints bound. ## Peaks and headroom Budget for the **peak**, not the average: the moment of export, a filter that needs a source and a destination at once, and a decode in progress overlap. One platform counts an app's memory by the pages it has actually written, so a buffer allocated but untouched may not count yet — and counts in full the moment the app fills it. Leave room for that, and for whatever another team's feature adds next release.

  • The OS publishes no memory limit; how do you choose the number this budget is checked against?
    Measure it. Run the heaviest session on the lowest-memory phone you support until the app is ended, and read field data on peak memory and on how often the app was ended for memory, by device class and version. Set the budget below that line with headroom, and where the platform reports the device's total RAM, scale the budget to it.
  • Why render the export in tiles when the full-resolution source is already in memory?
    Because the output needs a buffer too. Rendering the whole image at once means a second 192 MB buffer alongside the source, and a filter that reads one image and writes another doubles the peak exactly at export, when the app is most likely to be ended. Tiles of about 1 MB keep the extra memory to a few megabytes.

  • A photo needs about as much memory as its compressed file size
  • Undo needs a full-resolution bitmap snapshot for every step
  • A foreground app may use most of the phone's 3 GB
  • GPU textures are free because they live in separate graphics memory
  • Budgeting for the average screen is enough; the export peak can be ignored