




Memory is a hard constraint in mobile applications because devices have limited RAM and the OS may terminate apps that use too much memory. Interviewers ask this to evaluate whether you understand both language-level memory behavior and app-level resource management.
Explain how you handle memory management in a mobile application.
Address these points:
The interviewer expects a systems-oriented explanation rather than platform-specific trivia. Cover object lifetimes, references, lifecycle-aware cleanup, cache sizing, and low-memory handling. You should also mention trade-offs: aggressive caching improves speed but increases RAM pressure, while frequent reloading reduces memory but may hurt latency and battery.
Most mobile apps run in environments where memory is not manually freed in the C-style sense. Android commonly relies on garbage collection, while iOS uses ARC to manage object lifetimes through reference counting, but both still require developers to avoid retaining objects longer than needed.
class ImageHolder:
def __init__(self):
self.bitmap = None
holder = ImageHolder()
holder.bitmap = load_large_image()
A memory leak happens when objects are no longer useful but are still strongly referenced, so they cannot be reclaimed. In mobile apps, leaks often come from listeners, callbacks, static references, closures capturing screens, or background tasks outliving the UI.
listeners = []
def register(screen):
listeners.append(screen) # screen stays referenced forever if never removed
Screens, views, and background tasks should release resources when they are no longer visible or needed. Cleanup includes unregistering observers, canceling timers, stopping network work, and dropping references to large objects such as images or buffers.
def on_close(screen):
screen.timer.cancel()
screen.image_cache = None
Caching improves responsiveness, but unbounded caches are a common source of memory growth. A good strategy uses size-limited caches, eviction policies like LRU, and separate memory and disk caches so frequently used data stays fast without exhausting RAM.
from collections import OrderedDict
class LRUCache:
def __init__(self, capacity):
self.capacity = capacity
self.data = OrderedDict()
Memory issues should be validated with tools, not guesses. Heap snapshots, allocation tracking, leak detectors, and production telemetry help identify whether the problem is a true leak, temporary spike, fragmentation, or simply oversized assets.