Interactive Guide Apps, Memory & Storage

Comparing GC and ARC Through What Happens to Memory After Closing a Photo

Android collection times versus why a Swift screen fails to deallocate

Author: shaf Published Updated
  • Level: Intermediate
  • ~9 min read
  • 5 primary sources
  • Interactive model

Diagram showing a row of small pieces detaching from a cluster on the left, and small pieces linked by lines into a closed ring on the right
AI-generated conceptual diagram. The left illustrates reclaiming unreachable regions in batches; the right illustrates reference links forming a cycle. Use the interactive model below to adjust allocation rate and object lifetime and observe collection intervals.
Key Takeaway

After you close a photo screen, Android's GC marks data as eligible for reclamation once it is no longer reachable from roots, whereas Swift's ARC frees a class instance as soon as its last strong reference drops. Investigate pause timestamps if you see UI hitches, and trace retaining references if memory grows every time you reopen a screen.

Who this helps

  • Readers trying to figure out why an app's memory usage keeps climbing
  • Users wondering what actually separates Android and iPhone smoothness in comparisons

Decision checklist

  1. Read total GC duration separately from the interval during which the app was paused
  2. Trace retaining references to verify whether data is meant to stay alive after closing a screen

If you are shopping for a phone and want to compare CPU or GPU performance, pick the same benchmark suite and check the test devices — you don't need to infer hardware speed from GC counts.

Check test conditions for A19 Pro vs. Snapdragon 8 Elite Gen 5

Try the Interactive Model

Illustrative model (not measured data)

Same allocation and lifetime rules, different reclamation models.

Memory model parameters
GC collections6 runs
Model max pause0.74 ms
ARC reference ops684 ops
See when memory is reclaimed

Shared vertical axis. Vertical bands mark GC collection events; dots mark ARC reference operations. Band width and dot size do not represent execution time.

Illustrative memory usage for GC and ARCA / GC — Dead objects remain until collection050100B / ARC — Freed when lifetime ends0501000ms0ms400ms400ms800ms800ms1200ms1200ms
1 step = 20ms (illustrative time)

GC collections: 6; illustrative max pause: 0.74ms. ARC reference ops: 684. Shared deferred allocations: 0. At 0ms: GC 0, ARC 0 model units.

View collection events
  • 300ms: reclaimed 54 units, illustrative pause 0.74ms
  • 480ms: reclaimed 54 units, illustrative pause 0.74ms
  • 660ms: reclaimed 54 units, illustrative pause 0.74ms
  • 840ms: reclaimed 54 units, illustrative pause 0.74ms
  • 1020ms: reclaimed 54 units, illustrative pause 0.74ms
  • 1200ms: reclaimed 54 units, illustrative pause 0.74ms

Each object counts as 1 model unit; short-lived objects live for 3 steps and long-lived objects for 12 steps, with short-lived counts rounded to integers. ARC counts allocation and final reference release as 1 operation each; this model does not compare CPU execution time.

When You Close a Photo, When Is Its Image Data Freed?

Suppose you tap one photo from a gallery grid and then press Back. Even the instant the photo screen disappears, the gallery may still hold that image in memory in case you reopen it. A reference is a link pointing to data, and the heap is the memory region where objects created at runtime live. Separating whether something is visible on screen from whether it is still reachable through references makes the two models much easier to compare.

GC (Garbage Collection) automatically reclaims memory occupied by objects that are no longer used. ARC (Automatic Reference Counting) tracks ownership through strong references and deallocates a class instance once it is no longer needed. GC overview (Source 3) Swift ARC (Source 1)

AspectReachability-based GCSwift ARC
Liveness criterionWhether an object is reachable by following references from the running programWhether any strong reference still holds the instance
Management timingEvaluates reachability when a collection runsUpdates retention as references are acquired and released
After becoming unusedMemory may remain occupied until a collection occursCan be deallocated as soon as the last strong reference drops
Reference cyclesEligible for collection if unreachable from outsideStrong reference cycles stay alive and cannot be freed
Overhead to inspectCPU time spent collecting and app pause intervalsReference-counting/deallocation work and lingering references
DiagramTracing references to a photo one link at a timeConceptual flow for opening and closing a photo from a gallery in an app that uses an image cache.
  1. Open the photo

    The screen references the image. If a cache also points to the same image, there are two entry points.

  2. Close the screen

    Even after the screen drops its reference, the image can still be reused as long as the cache points to it.

  3. Check the last entry point

    Under GC, check whether roots can still reach it; under ARC, check whether any strong reference remains.

Comparing Heap Limits and Collection Counts in the Interactive Model

Open the GC vs. ARC model and keep the allocation rate fixed at 6. The table below records the results of running the same 60 steps. At a 70% short-lived ratio, the 6 objects per step are rounded to 4 short-lived and 2 long-lived objects. Here, the heap limit is expressed in number of objects.

Short-lived ratioHeap limitGC collectionsDeferred allocationsKey difference to notice
70%10060Default setup; finished objects stay until a collection runs
70%40520Lowering only the limit triggers frequent small collections
0%402430Once filled with live long-lived objects, collecting cannot make room for the next 6

In row 3, GC runs fewer times yet deferred allocations spike — because neither system can reclaim objects that are still in use to create free space. Allocation deferral is a shared model rule for both approaches and cannot be converted into real-world dropped frames or process kills. To see how pauses interact with display timing, compare 60 Hz and 120 Hz deadlines in the frame-pipeline model.

Display / settingMeaning in this modelHow it differs from real devices
Memory amountCounts 1 object as 1 model unitNot byte size or total OS memory usage
LifetimeFixed step counts based on short-lived / long-lived settingsDoes not simulate real reference graphs or cycles
GC collectionReclaims dead units when usage reaches ≥80% of limit or next allocation would exceed limitNot ART’s actual runtime thresholds
Pause band & valueMarks a collection event; duration uses 0.2 ms + reclaimed units × 0.01 msBand width is not drawn to scale with pause duration
ARC dotsModels reference operations corresponding to allocation and deallocationEach dot does not represent identical CPU cost

Whenever new allocations would exceed the limit, both modes defer that step’s allocations equally. As a result, one side appearing lower on the chart cannot be translated into product superiority or a required-RAM ratio.

GC Checks Whether an Object Is Reachable

To understand GC, reachability matters more than raw reference counts. Starting points held by the running program are called GC roots. Android Studio provides tools to trace which reference chain from a GC root keeps a given object alive. Inspecting roots and references (Source 4)

Cycles Are Still Collectible If Unreachable from Outside

Suppose A references B and B references A. If the program can reach either A or B from a root, that pair is still live. Once no path from any root reaches either one, pointing to each other alone does not make them usable by the program. Reachability-based collection can treat such isolated clusters as reclaimable memory. Purpose of GC (Source 3)

Conceptual reference example: A and B pointing to each other

Root → A ↔ B : reachable from a root

No path from root / A ↔ B : only mutual references remain

What separates GC and ARC is how they handle that second state. This is a conceptual example, not an actual heap layout.

Memory Leaks Still Happen Under GC

Even if an app no longer intends to use an object, GC considers it live as long as a long-lived cache or manager object still holds a reference to it. Automatic collection does not mean developers can ignore reference lifetimes.

Imagine a gallery that appends a reference to each opened screen into a tracking list without removing it on close. Every open/close cycle adds another retained screen. This is an illustrative example to explain the mechanism, not a bug reported in a specific app.

ARC Tracks Strong References: weak vs. unowned

In Swift’s ARC, strong references keep class instances alive. If A and B from above hold strong references to each other, removing outside references still leaves the cycle intact. Neither instance is freed — a strong reference cycle. Strong references and cycles (Source 1)

Avoiding cycles starts with deciding who owns whom. If a screen owns a helper object and the helper merely notifies the screen back, ask whether that back-reference needs to keep the screen alive.

Reference typeKeeps target alive?Lifetime consideration
strongYesTarget can remain alive until the owner releases the reference
weakNoAllows the target to deallocate first; becomes nil afterward
unownedNoRequires a design guarantee that the target stays alive whenever the reference is accessed

Do not treat unowned as a shorthand alternative to weak. Accessing a standard unowned reference after its target has been deallocated triggers a runtime error. Choose between them based on object lifetime relationships, not perceived speed. Rules for weak and unowned (Source 1)

Closures also deserve attention. If an object owns a closure that strongly captures self, the two form a cycle. Rather than mechanically adding weak everywhere, design explicitly around who guarantees survival until the closure finishes. Reference cycles in closures (Source 1)

Does Android’s GC Freeze Apps the Entire Time?

AOSP’s Concurrent Copying GC moves objects concurrently with app execution. The documentation also describes brief pauses and generational collection targeting young objects. Total collection duration and app pause duration are two different measurements. ART GC architecture (Source 2)

Here, “concurrent” means app work and GC work overlap in time — it does not mean “zero pauses everywhere.” Collection also consumes CPU and other resources, so looking only at pause time does not show the full performance cost.

Illustrative interpretation — not measured data

Suppose a collection takes 10 ms from start to finish, and the intervals where app threads paused total 1 ms. You cannot read that as “the app froze for 10 ms” — nor can you automatically assume “1 ms pause means negligible impact.”

What matters is when the pauses occurred, how long they lasted, what concurrent work ran alongside them, and how they aligned with rendering deadlines. These example figures are not ART standard values.

When investigating GC, correlate collection and pause records against the exact timestamp of the stutter. AOSP documentation shows how to aggregate GC runtime and pause times separately. Diagnosing pause times (Source 2)

During Development, Inspect Memory Size and Retention Together

Android: Find References That Outlive a Closed Screen

Capture a heap dump in Android Studio and inspect per-class allocations alongside the References pointing to suspect instances. Look not only at an object’s own size, but also at the memory retained because that object exists. Because capturing a heap dump itself adds overhead, keep it separate from frame-time profiling. Heap dump metrics and overhead (Source 4)

Swift: Trace Cycles with Debug Memory Graph

Xcode’s Debug Memory Graph visualizes allocated memory and the references connecting objects. Trace which reference is keeping an instance alive and verify whether it matches your intended lifecycle. Never treat the absence of memory warnings in the simulator as proof that a real device is safe. Xcode memory diagnostics (Source 5)

A practical reproduction pattern is: open the same screen → close it → repeat → compare what remains. A single memory bump cannot distinguish a deliberate cache from a leak. Defining upfront what should remain after closing the screen sharpens your investigation.

Decision FlowPick what to inspect next from memory or hitch symptomsA sequence for separating in-app memory reclamation from OS process management and frame deadlines.
  1. Does the app's memory usage keep climbing every time you open and close the same screen?

    Yes

    Trace retaining references (Heap Dump on Android, Memory Graph in Xcode)

    Distinguish intentional caching from leaks or reference cycles.
  2. Do you notice a brief hitch while scrolling or interacting with the screen?

    YesCorrelate pause timestamps against frame rendering deadlinesLook at pauses overlapping a frame deadline, not total GC duration.
  3. Does returning from another app force the app to start over from its initial screen?

    YesInvestigate process termination and UI state restorationTreat this as an OS-level lifecycle event separate from in-app GC.
  4. If you are comparing phones for an upgrade, compare matched benchmarks rather than inferring speed from GC versus ARC.

Keep OS Memory Management Separate from Chip Specifications

When comparing iPhone and Android behavior, separate memory management models (GC vs. ARC) from hardware specifications like CPU architecture and memory standards, checking each against official sources.

Specifications registered from official vendor documentation. Because Apple does not publish memory specifications for iPhone chips, that entry is shown as unlisted.
ChipCPU LayoutMemory TypeProcess Node
A19 ProApple Released 6-core (2x Performance + 4x Efficiency) Source Not listedNot listed
Snapdragon 8 Elite Gen 5Qualcomm Announced 8-core (2x Prime + 6x Performance) Source LPDDR5X Source 3nm Source Official generation name; foundry and sub-node details (such as N3P) are not listed.
Dimensity 9500MediaTek Announced 8-core (1x Prime + 7x Performance) Source LPDDR5X Source N3P Source

Match brief hitches right after closing a photo against display timestamps (how pauses affect frame deadlines). If returning from another app sends you back to the photo picker every time, move on to Android app retention and state restoration. When comparing OSes on upgrade candidates, breaking lag into input, rendering, and startup is also useful.

Frequently Asked Questions

If a GC log shows 10 ms, did the screen freeze for 10 ms?

Separate total elapsed collection time from the interval during which app threads were paused. Only after checking whether a pause overlapped with a rendering deadline can you evaluate its visual impact.

Why isn't a Swift class deallocated after closing the screen?

Even after a screen closes, the class stays alive if a cache or closure still holds a strong reference to it. Trace the owners in Xcode's Memory Graph to check whether those references should have ended.

How should I choose between weak and unowned?

Use weak and handle nil whenever the referenced object can be deallocated first. Use unowned only when your design guarantees the referenced object remains alive for the entire time the reference is used.

If an app restarts from the beginning when I switch back, is GC to blame?

GC reclaims memory inside a running process. Terminating an entire app process and restoring screen state happen at a different layer, so seeing a restarted screen alone does not indicate GC was the cause.

What is the biggest difference between GC and ARC?

GC decides what to reclaim based on reachability from GC roots, so a group of objects pointing only to each other without outside reachability can still be collected. Swift's ARC tracks strong references to each class instance and frees it when the last strong reference disappears, meaning a strong reference cycle cannot be freed automatically — you break it with weak or unowned.

Sources & Retrieval Dates