| <html devsite><head> |
| <title>调试本地内存使用</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 平台开发者使用 <a href="/devices/tech/debug/asan.html">AddressSanitizer</a> (ASan) 在 C/C++ 中查找内存错误。</p> |
| |
| <p></p>自 Android 8.0 (Oreo) 开始,您可以使用 ASan 在未取得 root 权限的正式版设备上对应用进行调试。您可以在 <a href="https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroidO">ASan wiki</a> 上找到相关说明。<p></p> |
| |
| <h2 id="malloc_debug">Malloc 调试</h2> |
| |
| <p>有关本地内存问题可用调试选项的完整说明,请参阅 <a href="https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README.md">Malloc 调试</a>和<a href="https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README_api.md">使用 libc 回调跟踪本地内存</a>。</p> |
| |
| <h2 id="malloc-stats">Malloc 统计信息</h2> |
| |
| <p> |
| Android 支持 <a href="http://man7.org/linux/man-pages/man3/mallinfo.3.html"><code>mallinfo(3)</code></a> 和 <a href="http://man7.org/linux/man-pages/man3/malloc_info.3.html"><code>malloc_info(3)</code></a> 扩展到 <code><malloc.h></code>。<code>malloc_info</code> 函数可在 Android 6.0 及更高版本中使用,其 XML 架构记录在 Bionic 的 <a href="https://android.googlesource.com/platform/bionic/+/master/libc/include/malloc.h"><code><malloc.h></code></a> 中。 |
| </p> |
| |
| <h2 id="ddms">Dalvik 调试监控服务器</h2> |
| |
| <p>您还可以使用 <a href="https://developer.android.com/studio/profile/ddms.html">Dalvik 调试监控服务器</a> (DDMS) 获取“Malloc 调试”输出的图形视图。</p> |
| |
| <p>要使用 DDMS,请先打开其本机内存界面:</p> |
| <ol> |
| <li>打开 <code>~/.android/ddms.cfg</code></li> |
| <li>添加命令行:<code>native=true</code></li> |
| </ol> |
| |
| <p>重新启动 DDMS 并选择一个进程后,您可以切换到新的本地分配选项卡,并使用分配列表进行填充。这对于调试内存泄漏尤为有用。</p> |
| |
| </body></html> |