blob: afa0d2201ce63538c4c89943b4cbdc585a0b49c0 [file] [log] [blame]
<html devsite>
<head>
<title>Debugging Native Memory Use</title>
<meta name="project_path" value="/_project.yaml" />
<meta name="book_path" value="/_book.yaml" />
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<h2 id="asan">Address Sanitizer</h2>
<p>Android platform developers use <a href="/devices/tech/debug/asan.html">AddressSanitizer</a>
(ASan) to find memory bugs in C/C++.</p>
</p>Since Android 8.0 (Oreo) it's also possible to use ASan to debug apps on non-rooted production
devices. You can find instructions on the
<a href="https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroidO">ASan wiki</a>.</p>
<h2 id="malloc_debug">Malloc debug</h2>
<p>See <a
href="https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README.md">Malloc
Debug</a> and <a
href="https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README_api.md">Native
Memory Tracking using libc Callbacks</a> for a thorough description of the
debugging options available for native memory issues.</p>
<h2 id="malloc-stats">Malloc statistics</h2>
<p>
Android supports the <a href="http://man7.org/linux/man-pages/man3/mallinfo.3.html"
><code>mallinfo(3)</code></a>and <a href="http://man7.org/linux/man-pages/man3/malloc_info.3.html"
><code>malloc_info(3)</code></a> extensions to <code>&lt;malloc.h&gt;</code></a>.
The <code>malloc_info</code> function is available in Android 6.0 and later and
its XML schema is documented in Bionic's
<a href="https://android.googlesource.com/platform/bionic/+/master/libc/include/malloc.h"
><code>&lt;malloc.h&gt;</code></a>.
</p>
<h2 id="ddms">Dalvik Debug Monitor Server</h2>
<p>You can also use the <a
href="https://developer.android.com/studio/profile/ddms.html">Dalvik Debug
Monitor Server</a> (DDMS) to obtain a graphical view of Malloc Debug
output.</p>
<p>To use DDMS, first turn on its native memory UI:</p>
<ol>
<li>Open <code>~/.android/ddms.cfg</code></li>
<li>Add the line: <code>native=true</code></li>
</ol>
<p>Upon relaunching DDMS and selecting a process, you can switch to the new
native allocation tab and populate it with a list of allocations. This is
especially useful for debugging memory leaks.</p>
</body>
</html>