Mobile Development 14 min read

Memory Management and Optimization Strategies for Gaode Map Mobile Application

To prevent iOS OOM kills in Gaode Map, developers analyzed Jetsam‑driven physical‑footprint data, identified IOKit, WebKit Malloc, and malloc‑heap as primary consumers, applied graphics texture trimming, shared JavaScriptCore contexts, hooked allocation APIs, and implemented adaptive resource management, achieving roughly 50 % memory reduction and lower crash rates.

Amap Tech
Amap Tech
Amap Tech
Memory Management and Optimization Strategies for Gaode Map Mobile Application

Background – According to Apple’s WWDC guidance, reducing memory usage improves app launch speed, prevents crashes, and extends app lifetime. For Gaode Map, high memory consumption leads to system‑initiated OOM kills (both foreground FOOM and background BOOM), severely affecting navigation stability.

Principle Analysis

OOM

OOM (Out of Memory) causes iOS to terminate the app without a catchable crash. Logs with the prefix JetsamEvent can be found under Settings → Privacy → Analytics & Improvements → Analytics Data, containing device, OS, memory size, CPU time, etc.

Jetsam

Jetsam is iOS’s resource‑management mechanism. When overall memory is tight, the system kills low‑priority or large‑memory processes. It uses get_task_phys_footprint to obtain phys_footprint and decides whether to kill an app.

Each process has a priority list; Jetsam starts killing from the lowest priority until memory pressure is relieved.

The decision is based on the physical footprint value.

Jetsam cleanup strategy includes:

Single‑app physical memory exceeding device‑specific thresholds is cleared.

When device memory is stressed, background apps are cleared before foreground apps.

Higher‑memory apps are cleared before lower‑memory ones.

User apps are prioritized over system apps.

Android counterpart – Low Memory Killer (LMK) uses oom_adj, oom_adj threshold, and oom_score_adj to decide which process to kill based on RSS.

Data Analysis

The phys_footprint API retrieves the total physical memory of an iOS app:

std::optional<size_t> memoryFootprint() {</code><code>    task_vm_info_data_t vmInfo;</code><code>    mach_msg_type_number_t count = TASK_VM_INFO_COUNT;</code><code>    kern_return_t result = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);</code><code>    if (result != KERN_SUCCESS)</code><code>        return std::nullopt;</code><code>    return static_cast<size_t>(vmInfo.phys_footprint);</code><code>}

Instruments‑VM Tracker can break down memory into categories such as Malloc heap, WebKit Malloc (JavaScriptCore), and IOKit (graphics). Gaode Map’s major memory consumers are IOKit, WebKit Malloc, and Malloc heap.

Optimization Strategies

Graphic Memory (IOKit) Optimization

Using Xcode’s Capture GPU Frame (iOS) or Google Graphics API Debugger (Android) to identify texture and buffer usage. Techniques include adjusting FBO rendering, optimizing large vector backgrounds, releasing icons across pages, text‑texture optimization, disabling full‑screen anti‑aliasing on low‑end devices, enabling low‑memory mode, disabling quadtree pre‑loading, and releasing cached resources when backgrounded.

WebKit Malloc (JavaScriptCore) Optimization

Gaode Map’s dynamic rendering engine relies on JavaScriptCore, which appears as WebKit Malloc in Instruments. Optimization can be done at the business level (reducing JS memory usage) and at the engine level (sharing a single JSContextGroupRef among multiple JSContextRef instances to avoid duplicate code loading).

Malloc Heap Optimization

iOS uses the libmalloc library. Relevant allocation APIs:

// C allocation functions</code><code>void *malloc(size_t __size) __result_use_check __alloc_size(1);</code><code>void *calloc(size_t __count, size_t __size) __result_use_check __alloc_size(1,2);</code><code>void free(void *);</code><code>void *realloc(void *__ptr, size_t __size) __result_use_check __alloc_size(2);</code><code>void *valloc(size_t) __alloc_size(1);</code><code></code><code>// Block allocation functions</code><code>// Create a heap‑based copy of a Block or add a reference to an existing one.</code><code>// Must be paired with Block_release.</code><code>BLOCK_EXPORT void *_Block_copy(const void *aBlock)</code><code>    __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);

Hooking these APIs or implementing malloc_logger (see definition below) allows recording allocation stacks and sizes for detailed analysis:

// Disable logging by setting malloc_logger to NULL</code><code>typedef void(malloc_logger_t)(uint32_t type,</code><code>        uintptr_t arg1,</code><code>        uintptr_t arg2,</code><code>        uintptr_t arg3,</code><code>        uintptr_t result,</code><code>        uint32_t num_hot_frames_to_skip);</code><code>extern malloc_logger_t *malloc_logger;

A complete Malloc analysis pipeline is built to handle high allocation rates, efficiently query, and aggregate stack traces for ownership attribution.

Unified Resource Management

A self‑adaptive resource‑management framework monitors device tier, system state, business scenario, and user behavior. It uses scheduling algorithms to allocate resources in real time, reclaiming memory from invisible components.

Data Acceptance

Three rounds of optimization yielded ~50% reduction in memory usage for both foreground and background navigation, and a 10‑20% decrease in abort rates. Ongoing monitoring is required to preserve these gains.

Long‑Term Control

An APM performance monitoring platform tracks memory, CPU, and network metrics, issuing alerts and integrating with a performance‑follow‑up process to catch regressions before release.

Memory Analysis Tools

Xcode Memory Gauge – quick overview of memory usage.

Instruments – Allocations, Leaks, VM Tracker, Virtual Memory Trace.

Memory Resource Exceptions – captures EXC_RESOURCE when memory exceeds limits.

Xcode Memory Debugger – visualizes object relationships and detects retain cycles.

memgraph + command‑line tools (vmmap, leaks, heap, malloc_history) – deep inspection of VM regions and heap objects.

MetricKit – iOS 13+ framework for battery and performance metrics.

MLeaksFinder – non‑intrusive leak detection via view controller lifecycle.

Graphics API Debugger (Google) and Arm Mobile Studio – GPU‑level analysis.

iOSmemory managementOOMGaode MapJetsam
Amap Tech
Written by

Amap Tech

Official Amap technology account showcasing all of Amap's technical innovations.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.