1 <html devsite> 2 <head> 3 <title>Debugging Native Memory Use</title> 4 <meta name="project_path" value="/_project.yaml" /> 5 <meta name="book_path" value="/_book.yaml" /> 6 </head> 7 <body> 8 <!-- 9 Copyright 2017 The Android Open Source Project 10 11 Licensed under the Apache License, Version 2.0 (the "License"); 12 you may not use this file except in compliance with the License. 13 You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 --> 23 24 25 <h2 id="malloc_debug">Malloc debug</h2> 26 27 <p>See <a 28 href="https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README.md">Malloc 29 Debug</a> and <a 30 href="https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README_api.md">Native 31 Memory Tracking using libc Callbacks</a> for a thorough description of the 32 debugging options available for native memory issues.</p> 33 34 <h2 id="malloc-stats">Malloc statistics</h2> 35 36 <p> 37 Android supports the <a href="http://man7.org/linux/man-pages/man3/mallinfo.3.html" 38 ><code>mallinfo(3)</code></a>and <a href="http://man7.org/linux/man-pages/man3/malloc_info.3.html" 39 ><code>malloc_info(3)</code></a> extensions to <code><malloc.h></code></a>. 40 The <code>malloc_info</code> function is available in Android 6.0 and later and 41 its XML schema is documented in Bionic's 42 <a href="https://android.googlesource.com/platform/bionic/+/master/libc/include/malloc.h" 43 ><code><malloc.h></code></a>. 44 </p> 45 46 <h2 id="ddms">Dalvik Debug Monitor Server</h2> 47 48 <p>You can also use the <a 49 href="https://developer.android.com/studio/profile/ddms.html">Dalvik Debug 50 Monitor Server</a> (DDMS) to obtain a graphical view of Malloc Debug 51 output.</p> 52 53 <p>To use DDMS, first turn on its native memory UI:</p> 54 <ol> 55 <li>Open <code>~/.android/ddms.cfg</code></li> 56 <li>Add the line: <code>native=true</code></li> 57 </ol> 58 59 <p>Upon relaunching DDMS and selecting a process, you can switch to the new 60 native allocation tab and populate it with a list of allocations. This is 61 especially useful for debugging memory leaks.</p> 62 63 </body> 64 </html> 65