Mulai 27 Maret 2025, sebaiknya gunakan android-latest-release
, bukan aosp-main
, untuk mem-build dan berkontribusi pada AOSP. Untuk mengetahui informasi selengkapnya, lihat Perubahan pada AOSP.
Men-debug penggunaan memori native
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Address Sanitizer: HWASan/ASan
Developer platform Android menggunakan HWAddressSanitizer
(HWASan) untuk menemukan bug memori di C/C++.
Anda dapat mem-flash image HWASan bawaan ke perangkat Pixel yang didukung dari
ci.android.com (petunjuk penyiapan mendetail).
Mulai Android 8.0 (Oreo), ASan dapat digunakan untuk men-debug aplikasi pada perangkat produksi
yang tidak di-root. Anda dapat menemukan petunjuknya di
ASan wiki.
Heapprofd
Android 10 mendukung heapprofd, profiler heap sampling dengan overhead rendah.
heapprofd memungkinkan Anda mengatribusikan penggunaan memori native ke callstack dalam program Anda.
Lihat
heapprofd - Android Heap Profiler di
situs dokumentasi Perfetto
untuk mengetahui informasi selengkapnya.
Malloc debug
Lihat Malloc
Debug dan Pelacakan
Memori Native menggunakan Callback libc untuk mendapatkan deskripsi lengkap tentang
opsi proses debug yang tersedia untuk masalah memori native.
libmemunreachable
libmemunreachable Android adalah detektor kebocoran memori native tanpa overhead.
Alat ini menggunakan garbage collector mark-and-sweep yang tidak akurat yang melewati semua memori native,
melaporkan blok yang tidak dapat dijangkau sebagai kebocoran. Lihat
dokumentasi libmemunreachable untuk mendapatkan petunjuk penggunaan.
Malloc hooks
Jika Anda ingin membuat alat sendiri, libc Android juga mendukung intersepsi semua
panggilan alokasi/gratis yang terjadi selama eksekusi program. Lihat
dokumentasi
malloc_hooks untuk mendapatkan petunjuk penggunaan.
Statistik malloc
Android mendukung ekstensi mallinfo(3)
dan malloc_info(3)
ke <malloc.h>
.
Fungsi malloc_info
tersedia di Android 6.0 (Marshmallow) dan yang lebih tinggi serta
skema XML-nya didokumentasikan dalam
<malloc.h>
Bionic.
Server Dalvik Debug Monitor
Anda juga dapat menggunakan Dalvik Debug
Monitor Server (DDMS) untuk mendapatkan tampilan grafis output Malloc Debug.
Untuk menggunakan DDMS, aktifkan UI memori native-nya terlebih dahulu:
- Buka
~/.android/ddms.cfg
- Tambahkan baris:
native=true
Setelah meluncurkan kembali DDMS dan memilih proses, Anda dapat beralih ke tab
alokasi native baru dan mengisinya dengan daftar alokasi. Hal ini
sangat berguna untuk men-debug kebocoran memori.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-27 UTC."],[],[],null,["# Debug native memory use\n\nAddress Sanitizer: HWASan/ASan\n------------------------------\n\nAndroid platform developers use [HWAddressSanitizer](/docs/security/test/hwasan)\n(HWASan) to find memory bugs in C/C++.\n\nYou can flash prebuilt HWASan images to supported Pixel devices from\n[ci.android.com](https://ci.android.com/builds/branches/aosp-master-with-phones-throttled/grid?) ([detailed setup instructions](https://developer.android.com/ndk/guides/hwasan)).\n\nSince 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 [ASan wiki](https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroidO).\n\n\u003cbr /\u003e\n\nHeapprofd\n---------\n\nAndroid 10 supports heapprofd, a low-overhead, sampling heap profiler.\nheapprofd lets you attribute native memory usage to callstacks in your program.\nSee [heapprofd - Android Heap Profiler](https://docs.perfetto.dev/#/heapprofd) on the\n[Perfetto documentation site](https://docs.perfetto.dev/#/)\nfor more information.\n\nMalloc debug\n------------\n\nSee [Malloc\nDebug](https://android.googlesource.com/platform/bionic/+/android16-release/libc/malloc_debug/README.md) and [Native\nMemory Tracking using libc Callbacks](https://android.googlesource.com/platform/bionic/+/android16-release/libc/malloc_debug/README_api.md) for a thorough description of the\ndebugging options available for native memory issues.\n\nlibmemunreachable\n-----------------\n\nAndroid's libmemunreachable is a zero-overhead native memory leak detector.\nIt uses an imprecise mark-and-sweep garbage collector pass over all native memory,\nreporting any unreachable blocks as leaks. See the\n[libmemunreachable\ndocumentation](https://android.googlesource.com/platform/system/memory/libmemunreachable/+/android16-release/README.md) for usage instructions.\n\nMalloc hooks\n------------\n\nIf you want to build your own tools, Android's libc also supports intercepting all\nallocation/free calls that happen during program execution. See the\n[malloc_hooks\ndocumentation](https://android.googlesource.com/platform/bionic/+/android16-release/libc/malloc_hooks/README.md) for usage instructions.\n\nMalloc statistics\n-----------------\n\n\nAndroid supports the [`mallinfo(3)`](http://man7.org/linux/man-pages/man3/mallinfo.3.html)and [`malloc_info(3)`](http://man7.org/linux/man-pages/man3/malloc_info.3.html) extensions to `\u003cmalloc.h\u003e`.\nThe `malloc_info` function is available in Android 6.0 (Marshmallow) and higher and\nits XML schema is documented in Bionic's\n[`\u003cmalloc.h\u003e`](https://android.googlesource.com/platform/bionic/+/android16-release/libc/include/malloc.h).\n\nDalvik Debug Monitor Server\n---------------------------\n\nYou can also use the [Dalvik Debug\nMonitor Server (DDMS)](https://developer.android.com/studio/profile/ddms.html) to obtain a graphical view of Malloc Debug\noutput.\n\nTo use DDMS, first turn on its native memory UI:\n\n1. Open `~/.android/ddms.cfg`\n2. Add the line: `native=true`\n\nUpon relaunching DDMS and selecting a process, you can switch to the new\nnative allocation tab and populate it with a list of allocations. This is\nespecially useful for debugging memory leaks."]]