2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
네이티브 메모리 사용 디버그
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Address Sanitizer(HWASan/ASan)
Android 플랫폼 개발자는 HWAddressSanitizer(HWASan)를 사용하여 C/C++에서 메모리 버그를 찾습니다.
미리 빌드된 HWASan 이미지를 ci.android.com에서 지원되는 Pixel 기기에 플래시할 수 있습니다(자세한 설정 안내).
Android 8.0(Oreo)부터는 루팅되지 않은 프로덕션 기기에서 ASan을 사용해 앱을 디버깅할 수도 있습니다. 자세한 안내는
ASan 위키를 참조하세요.
Heapprofd
Android 10은 오버헤드가 낮은 샘플링 힙 프로파일러인 heapprofd를 지원합니다. heapprofd를 사용하면 네이티브 메모리 사용량을 프로그램의 호출 스택에 표시할 수 있습니다.
자세한 내용은 Perfetto 문서 사이트에서 heapprofd - Android 힙 프로파일러를 참조하세요.
Malloc 디버그
네이티브 메모리 문제에 사용할 수 있는 디버깅 옵션에 관한 자세한 설명은 Malloc 디버그와 libc 콜백을 사용한 네이티브 메모리 추적을 참조하세요.
libmemunreachable
Android의 libmemunreachable은 오버헤드가 발생하지 않는 네이티브 메모리 누수 감지기입니다.
모든 네이티브 메모리에 부정확한 마크 앤 스윕 가비지 컬렉터 패스를 사용하여 연결할 수 없는 블록을 누수로 보고합니다. 사용법 안내는 libmemunreachable 문서를 참조하세요.
Malloc 후크
나만의 도구를 빌드하려는 경우 Android의 libc에서도 프로그램을 실행하는 동안 발생하는 모든 할당/자유 호출의 가로채기를 지원합니다. 사용법 안내는 malloc_hooks 문서를 참조하세요.
Malloc 통계
Android는 <malloc.h>
에 대한 mallinfo(3)
및 malloc_info(3)
확장을 지원합니다.
malloc_info
함수는 Android 6.0(Marshmallow) 이상에서 사용할 수 있으며 이 함수의 XML 스키마는 Bionic의 <malloc.h>
에 문서화되어 있습니다.
Dalvik 디버그 모니터 서버
Dalvik 디버그 모니터 서버 (DDMS)를 사용하여 Malloc 디버그 출력을 그래픽 뷰로 볼 수도 있습니다.
DDMS를 사용하려면 다음 단계에 따라 먼저 네이티브 메모리 UI를 사용 설정하세요.
~/.android/ddms.cfg
열기
native=true
행을 추가합니다.
DDMS를 다시 실행하고 프로세스를 선택하면 새 기본 할당 탭으로 전환하여 할당 목록을 채울 수 있습니다. 이 방법은 특히 메모리 누수를 디버깅할 때 유용합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 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."]]