Two photographs of the same roof arrive as modest JPEG attachments. An assessor opens them side by side on a tablet, zooms into the flashing and swipes to the next pair. The first comparison feels instant. By the fourth or fifth pair, the app may stall or disappear. Checking the total size of the JPEG files in the download folder is a tempting first move. It measures a different resource from the one that the comparison view is consuming.
Take a 6000 by 4000 image decoded into a tightly packed four-byte-per-pixel buffer. Multiplying the dimensions by four gives 96,000,000 bytes, about 91.6 MiB. Two such buffers require about 183.1 MiB before counting row alignment, graphics resources, thumbnails or anything else in the process. A decoder that temporarily holds both an old and a new comparison pair can exceed 366 MiB in those four buffers alone. These are arithmetic estimates for a stated format, not measurements of a particular tablet.
Put dimensions beside every ownership claim
Draw the short life of one photo. Compressed bytes reach a file. A decoder opens it and produces a buffer. A view holds a reference while drawing; a memory cache may retain another reference for a return visit. An editor might allocate a separate surface to adjust brightness. Two references to the same buffer do not automatically double its cost. Two independent decodes of the same file can. Give each traced decode a request identity, output dimensions, pixel format and owner so the trace can distinguish the two cases.
Add a time axis to this sketch. A screenshot after the next pair settles tells you what survives in steady state. The dangerous peak can occur earlier, while a crossfade still draws the old pair and new results arrive. Disable the transition for one diagnostic run. If the peak drops, investigate how long the transition retains the outgoing surfaces. If it barely changes, inspect requests queued by adjacent pages, duplicate thumbnail loads and the editor. A disabled animation can be a useful experiment without becoming the final design.
Memory budgets vary with device, operating system and other running work. Start with measurements on a supported lower-memory tablet while it is doing an ordinary inspection. Record the baseline before opening the gallery, the highest value during a pair change and the level after the assessor leaves the screen. Use comparable builds and the same photo set. A development profiler, a cold file cache and a release build can give different timings; write down which conditions produced the trace.
Size the first decode for the decision on screen
In this example each comparison pane initially draws its photograph in a rectangle 1200 by 800 physical pixels. A matching four-byte buffer is 3,840,000 bytes, about 3.66 MiB. Two previews cost about 7.32 MiB in that format. The reduction relative to the full pair is substantial, yet the previews can still answer the first question: are these photographs of the same section of roof? The assessor only needs fine detail after choosing the area around the flashing.
Compute a requested size from the measured target, its pixel density and the intended scaling mode. A logical width reported by layout cannot be treated interchangeably with a physical pixel width. For a fill-and-crop thumbnail, account for the source aspect ratio and the crop the assessor will see. A wide panorama fitted into a square has different requirements from a portrait that must fill it. Store the source’s orientation and apply it consistently when selecting the decode size and drawing the result.
During a continuous resize, many nearly identical dimensions may arrive in a second. Starting a fresh decode for every intermediate width consumes bandwidth, CPU and temporary buffers. Reuse the current preview during the drag and request a better-sized representation when it matters. A small set of size buckets can reduce cache churn. Keep the ability to serve a larger preview when the assessor actually widens a pane or uses an external display. A permanent tiny preview saves memory at the cost of unreadable evidence.
Let a zoom gesture buy detail locally
At high magnification the assessor is inspecting a patch of roof, while most of the original image lies outside the viewport. Where the format and image pipeline support it, a tiled representation can supply higher detail for the visible region and a small margin around it. At four bytes per pixel a 512 by 512 tile contains exactly one MiB of unpadded pixel data. Twelve such tiles represent twelve MiB before overhead. Doubling the tile edge quadruples that per-tile figure.
A tile key needs the source revision, resolution level and tile position. Apply an orientation or crop before defining the grid, or carry an explicit mapping from grid coordinates to the original. Otherwise rotating a portrait source can cause a sharp tile of roof gutter to be drawn over an unrelated piece of sky. Borders between scaled tiles need a visual check at fractional zoom. A thin seam can be a sampling artefact even when the returned tile coordinates are correct.
When users pan rapidly, prioritize the currently exposed area. Cancel or demote requests that have fallen well behind the viewport. A cancelled request may still finish inside a decoder that cannot stop immediately. Before installing the output, compare its source revision and view request with the active comparison. Discard obsolete results and release their resources according to the image pipeline’s ownership rules. Without the identity check, a slow result for an old roof can briefly replace the new roof in the right pane.
Choose what can be evicted
Original evidence, unsaved edits, disk previews and decoded surfaces have different recovery costs. Persist the original according to the product’s retention rules. Store crop rectangles, labels or exposure adjustments as edits tied to that original when the workflow allows. Treat a derived contact sheet as replaceable. On a memory warning the app can then discard off-screen representations without erasing the assessor’s changes or forcing another download of the entire assignment.
Bound the memory cache in bytes. A limit of twenty images has little predictive value if the cache mixes square thumbnails and revision-quality previews. Account for the actual allocation when the framework exposes it, and understand which resources the cache measurement excludes. Keep a separate ceiling on concurrent decodes: a perfectly bounded cache may still be overwhelmed by eight workers allocating independent outputs before any of them inserts a result into that cache.
Inspect navigation ownership during a long session. A screen that has been closed can still be retained by a callback, pending transform or observer. Repeat “open comparison, close comparison” against the same images, waiting for active tasks to settle between cycles. A plateau can be consistent with a warm cache. A rising baseline warrants examining retained owners and cache keys. Each new key containing a transient screen identifier can defeat reuse even in the absence of a conventional reference leak.
What happens when the original is needed?
A damage report may require an export at full resolution. Budget this operation separately from browsing. Suspend unnecessary prefetch, limit how many exports run at once and use a streaming or tiled processing path where the encoder supports it. Confirm the output dimensions and orientation by reopening the exported file. Exporting the on-screen preview is an easy way to pass a visual test on the tablet while delivering an image too small for the assessor’s downstream workflow.
A failed export should leave the source and prior completed report recoverable. Write the new output to a temporary destination when the storage system supports safe replacement, validate completion and only then expose it as the finished report. Test running out of storage as well as memory pressure. The UI can display an attractive final preview long before the final file is complete. “Exported” should refer to a completed output that a colleague can actually open.
One useful recovery test interrupts export after the first of two photos completes. On reopening the assignment, the assessor should be able to distinguish the completed output, the pending one and any changes that remain local. Make retry operate on the correct source revisions. If someone edited the crop between attempts, decide whether retry finishes the old report or begins a new revision. The memory optimisation is of limited value if it silently changes which evidence the report contains.
Read the trace like a sequence of decisions
Build a reference album containing a tall portrait, an unusually wide panorama, two nearly identical shots and a file with orientation metadata. Include an unreadable file so failure paths release resources too. Run cold browsing, repeated back-and-forth comparison, continuous resizing, a long zoom and final export. For each phase, record peak process memory, decode dimensions, active workers, visible pixel quality and time until the assessor can act. A single average for the whole run can hide the moment the old pair and new pair overlap.
If the peak occurs before either new photograph is visible, check the request queue and allocation timeline. If memory returns to baseline but scrolling still stutters, inspect decode scheduling and rendering time. If the final comparison looks crisp yet the export looks soft, inspect the source selected by the encoder. These observations lead to different fixes. The practical acceptance test ends with the assessor zooming into the flashing, switching pairs several times and opening a full-resolution report whose evidence matches the chosen photographs.
Platform background: Android graphics and bitmap handling.