Memory usage is the RAM occupied while an application runs. Excessive use slows garbage collection, drains battery, destabilizes long-running apps, starves other processes, and can trigger operating-system termination. The risk depends on the device or service capacity, so the useful question is not whether memory is nonzero but whether it remains within a measured limit during realistic work. section 3.2.3 section 6.2.1
Treat memory as a budget with checkpoints rather than a late-stage cleanup task. Measure a baseline after initial load, measure typical operation and peak work, then measure again after an extended session. A stable post-session result indicates cleanup is keeping pace; continued growth points to a leak or retained data. Leave explicit headroom for complex operations and require new features to fit the budget or justify a trade-off. section 6.2.1 section 6.9
Set limits according to the operating context:
- Mobile: keep peak consumption low enough to avoid termination on constrained devices; simple and media-heavy apps need different allowances. section 3.2.3 section 6.2.1
- Backend: derive an instance budget from expected concurrency and per-request peak consumption, because memory use constrains capacity and response predictability. section 6.2.1
- Desktop: test for hours as well as minutes. Small hourly growth can make an all-day application unusable even when startup behavior looks normal. section 5.2.3 section 7.4.1
Find a retained-screen leak
To profile a repeated mobile action, mark a memory-generation baseline, navigate to a screen and back, then inspect allocations made since the mark. Repeat the action. If retained objects or total memory rise each time instead of returning near baseline, inspect leak paths for strong-reference cycles, closures, delegates, or listeners that keep objects alive. In one account-overview workflow, unreleased transaction data and decoded images added 8MB on every return. section 7.3.3
Use snapshots to distinguish expected allocation from harmful growth. Capture memory after startup, after a normal workflow returns to idle, and later during typical use; compare the snapshots and associate changes with user actions. For a batch process, watch whether each item is released before the next loads. A desktop image export that rose from 180MB to 2.1GB was corrected by clearing per-image undo history and freeing image data, stabilizing near 250MB. section 7.4.1 section 7.4.3
Table 7.2 Backend profiling concerns, tools, and diagnostic patterns
|
Concern
|
Tools by language
|
What to look for
|
|
CPU hotspots
|
Python: cProfile[1], py-spy[2]
Node.js: --prof[3], clinic[4]
Go: pprof[5]
Java: async-profiler[6],
Java Flight Recorder[7]
|
Functions taking longer than expected, functions call with
unexpected frequency, work on hot paths that could be cached
|
|
Memory behavior
|
Python: tracemalloc[8],
memory_profiler[9]
Node.js: heap snapshots[10]
Go: pprof heap
Java: VisualVM[11], Eclipse
MAT[12]
|
Continuous growth without leveling off, objects that
accumulate across requests, container memory approaching limits
|
|
Database queries
|
Query logging, EXPLAIN/EXPLAIN ANALYZE, Object-relational
mapper (ORM) debug modes
|
N+1 patterns, sequential scans on large tables, missing
indexes, queries returning more data than needed
|
|
Connection management
|
Pool metrics from your database driver
|
Pool exhaustion under load, connections held too long,
connection leaks from error paths
|
Backend memory profiling looks for continuous growth that never levels off, objects accumulating across requests, and container memory nearing its limit. Select tools appropriate to the runtime, then correlate heap behavior with request patterns before changing code. section 7.2
Make memory accountability operational. Record the current baseline before setting a threshold, set budgets tighter than the user-facing goal to expose regressions early, assign owners for routine decisions and exceptions, and review breaches regularly. When a limit breaks, diagnose the cause and reset it deliberately rather than silently normalizing the regression. section 6.9












