{"id":99116,"date":"2026-09-01T23:42:42","date_gmt":"2026-09-01T15:42:42","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/99116.html"},"modified":"2026-09-01T23:42:42","modified_gmt":"2026-09-01T15:42:42","slug":"android-memory-profiler%ef%bc%9a%e5%a0%86%e5%86%85%e5%ad%98%e6%8c%87%e6%a0%87%e3%80%81%e5%86%85%e5%ad%98%e6%8a%96%e5%8a%a8%e4%b8%8e%e6%b3%84%e6%bc%8f%e5%ae%9a%e4%bd%8d","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/99116.html","title":{"rendered":"Android Memory Profiler\uff1a\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d"},"content":{"rendered":"<\/p>\n<hr \/>\n<h2>Android Memory Profiler&#xff1a;\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d<\/h2>\n<ul>\n<li>Android Memory Profiler&#xff1a;\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d<\/li>\n<li>1. \u9605\u8bfb\u524d\u95ee\u9898\u5361&#xff1a;Memory Profiler \u5185\u5b58\u5206\u6790\n<ul>\n<li>1.1 \u9605\u8bfb\u524d\u5148\u770b\u8fd9\u51e0\u4e2a\u95ee\u9898<\/li>\n<li>1.2 \u8bfb\u5b8c\u540e\u5b8c\u6210\u8fd9 3 \u9053\u9ad8\u9891\u95ee\u9898<\/li>\n<li>1.3 \u81ea\u68c0\u6e05\u5355<\/li>\n<\/ul>\n<\/li>\n<li>2. \u524d\u8a00\n<ul>\n<li>2.1 \u770b\u6e05\u4e00\u4e2a\u5bf9\u8c61\u5360\u7528\u548c\u7275\u8fde\u7684\u5185\u5b58<\/li>\n<li>2.2 \u4ece\u6ce2\u52a8\u548c\u5206\u914d\u8bb0\u5f55\u5b9a\u4f4d\u5185\u5b58\u6296\u52a8<\/li>\n<li>2.3 \u6cbf\u5f15\u7528\u94fe\u786e\u8ba4\u5185\u5b58\u6cc4\u6f0f<\/li>\n<\/ul>\n<\/li>\n<li>3. Native Size\u3001Shallow Size\u3001Retained Size \u4e0e Depth<\/li>\n<li>4. Memory Profiler\n<ul>\n<li>4.1 Memory Profiler \u754c\u9762\u8bf4\u660e<\/li>\n<li>4.2 Memory Profiler \u67e5\u627e\u5185\u5b58\u6296\u52a8<\/li>\n<li>4.3 Memory Profiler \u67e5\u627e\u5185\u5b58\u6cc4\u6f0f<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5efa\u8bae\u5148\u8bfb&#xff1a;\u5148\u7406\u89e3\u7b2c 3 \u8282\u7684\u56db\u4e2a\u5806\u5185\u5b58\u6307\u6807&#xff0c;\u518d\u8fdb\u5165\u7b2c 4 \u8282\u89c2\u5bdf\u5185\u5b58\u66f2\u7ebf\u3001\u5206\u914d\u8c03\u7528\u6808\u548c\u5f15\u7528\u94fe\u3002<\/p>\n<\/p>\n<hr \/>\n<h3>1. \u9605\u8bfb\u524d\u95ee\u9898\u5361&#xff1a;Memory Profiler \u5185\u5b58\u5206\u6790<\/h3>\n<\/p>\n<hr \/>\n<h4>1.1 \u9605\u8bfb\u524d\u5148\u770b\u8fd9\u51e0\u4e2a\u95ee\u9898<\/h4>\n<li>Native Size\u3001Shallow Size\u3001Retained Size \u5206\u522b\u7edf\u8ba1\u54ea\u4e00\u90e8\u5206\u5185\u5b58&#xff1f;<\/li>\n<li>Depth \u8868\u793a\u4ec0\u4e48&#xff0c;\u4e3a\u4ec0\u4e48 Depth \u4e3a 1 \u7684\u5b9e\u4f8b\u5c24\u5176\u503c\u5f97\u8b66\u60d5&#xff1f;<\/li>\n<li>\u5185\u5b58\u6296\u52a8\u548c\u5185\u5b58\u6cc4\u6f0f\u5728 Memory Profiler \u4e2d\u5206\u522b\u5448\u73b0\u4ec0\u4e48\u7279\u5f81&#xff1f;<\/li>\n<li>\u5982\u4f55\u901a\u8fc7 Allocations\u3001Instance View \u548c Allocation Call Stack \u5b9a\u4f4d\u9891\u7e41\u521b\u5efa\u5bf9\u8c61\u7684\u4ee3\u7801\u4f4d\u7f6e&#xff1f;<\/li>\n<li>\u4e3a\u4ec0\u4e48\u5f55\u5236\u5185\u5b58\u5206\u914d\u6216\u751f\u6210 Heap Dump \u524d\u901a\u5e38\u8981\u5148\u624b\u52a8\u6267\u884c GC&#xff1f;<\/li>\n<li>Heap Dump \u4e2d\u4ecd\u5b58\u5728\u591a\u4e2a\u672c\u5e94\u9500\u6bc1\u7684 Activity \u5b9e\u4f8b\u65f6&#xff0c;\u5982\u4f55\u501f\u52a9 Reference \u5224\u65ad\u662f\u5426\u53d1\u751f\u6cc4\u6f0f&#xff1f;<\/li>\n<hr \/>\n<h4>1.2 \u8bfb\u5b8c\u540e\u5b8c\u6210\u8fd9 3 \u9053\u9ad8\u9891\u95ee\u9898<\/h4>\n<hr \/>\n<p>1.2.1 \u9ad8\u9891\u95ee\u9898 1&#xff1a;\u8bf7\u8bf4\u660e Native Size\u3001Shallow Size\u3001Retained Size \u548c Depth \u7684\u542b\u4e49\u53ca\u5b83\u4eec\u5728\u5206\u6790\u5bf9\u8c61\u5185\u5b58\u65f6\u7684\u5173\u7cfb\u3002<\/p>\n<hr \/>\n<p>1.2.2 \u9ad8\u9891\u95ee\u9898 2&#xff1a;\u5982\u4f55\u4f7f\u7528 Memory Profiler \u7684\u5185\u5b58\u66f2\u7ebf\u3001\u5bf9\u8c61\u5206\u914d\u6570\u91cf\u548c\u5206\u914d\u8c03\u7528\u6808\u5b9a\u4f4d\u5185\u5b58\u6296\u52a8&#xff1f;<\/p>\n<hr \/>\n<p>1.2.3 \u9ad8\u9891\u95ee\u9898 3&#xff1a;\u5185\u5b58\u6cc4\u6f0f\u5728 Memory Profiler \u4e2d\u6709\u54ea\u4e9b\u8868\u73b0&#xff0c;\u5982\u4f55\u901a\u8fc7 Heap Dump\u3001\u5b9e\u4f8b\u5217\u8868\u548c\u5f15\u7528\u94fe\u786e\u8ba4\u6cc4\u6f0f\u4f4d\u7f6e&#xff1f;<\/p>\n<\/p>\n<hr \/>\n<h4>1.3 \u81ea\u68c0\u6e05\u5355<\/h4>\n<ul>\n<li class=\"task-list-item\"> \u80fd\u533a\u5206 Native Size\u3001Shallow Size \u548c Retained Size \u7684\u7edf\u8ba1\u8303\u56f4\u3002<\/li>\n<li class=\"task-list-item\"> \u80fd\u89e3\u91ca\u5bf9\u8c61\u7684 Depth \u4e0e GC Root \u6700\u77ed\u5f15\u7528\u8def\u5f84\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/li>\n<li class=\"task-list-item\"> \u80fd\u6839\u636e\u5185\u5b58\u66f2\u7ebf\u533a\u5206\u9891\u7e41 GC\u3001\u9636\u68af\u5f0f\u589e\u957f\u548c\u6b63\u5e38\u6ce2\u52a8\u3002<\/li>\n<li class=\"task-list-item\"> \u80fd\u590d\u8ff0\u4ece\u5f55\u5236\u5185\u5b58\u5230\u5b9a\u4f4d\u5206\u914d\u8c03\u7528\u6808\u7684\u5b8c\u6574\u6b65\u9aa4\u3002<\/li>\n<li class=\"task-list-item\"> \u80fd\u8bf4\u660e\u4e3a\u4ec0\u4e48 Heap Dump \u524d\u8981\u5148 GC&#xff0c;\u4ee5\u53ca\u600e\u6837\u5224\u65ad\u591a\u4e2a Activity \u5b9e\u4f8b\u662f\u5426\u5f02\u5e38\u5b58\u6d3b\u3002<\/li>\n<li class=\"task-list-item\"> \u80fd\u6cbf Reference \u5c55\u793a\u7684\u5f15\u7528\u94fe\u8bf4\u660e\u5bf9\u8c61\u4e3a\u4ec0\u4e48\u6ca1\u6709\u88ab\u56de\u6536\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>2. \u524d\u8a00<\/h3>\n<\/p>\n<hr \/>\n<h4>2.1 \u770b\u6e05\u4e00\u4e2a\u5bf9\u8c61\u5360\u7528\u548c\u7275\u8fde\u7684\u5185\u5b58<\/h4>\n<p>\u642c\u5bb6\u65f6&#xff0c;\u4e00\u4ef6\u5bb6\u5177\u672c\u8eab\u5360\u591a\u5c11\u7a7a\u95f4\u3001\u5b83\u9644\u5e26\u7684\u5305\u88c5\u5360\u591a\u5c11\u7a7a\u95f4&#xff0c;\u4ee5\u53ca\u79fb\u8d70\u5b83\u540e\u80fd\u4e00\u5e76\u817e\u51fa\u591a\u5c11\u7a7a\u95f4&#xff0c;\u662f\u4e09\u4e2a\u4e0d\u540c\u7684\u95ee\u9898\u3002\u8fd8\u53ef\u4ee5\u7ee7\u7eed\u8ffd\u95ee&#xff1a;\u4ece\u4ed3\u5e93\u51fa\u53e3\u5230\u8fd9\u4ef6\u5bb6\u5177&#xff0c;\u6700\u77ed\u8981\u7ecf\u8fc7\u51e0\u9053\u95e8\u3002<\/p>\n<p>\u5728\u5806\u5185\u5b58\u5206\u6790\u4e2d&#xff0c;\u8fd9\u51e0\u7c7b\u89c2\u5bdf\u5206\u522b\u5bf9\u5e94\u5bf9\u8c61\u672c\u8eab\u7684 Shallow Size\u3001\u5bf9\u8c61\u5f15\u7528\u7684\u539f\u751f\u5bf9\u8c61\u6240\u5360\u7684 Native Size\u3001\u5220\u9664\u5bf9\u8c61\u540e\u53ef\u968f\u4e4b\u56de\u6536\u7684 Retained Size&#xff0c;\u4ee5\u53ca\u4ece GC Root \u5230\u5b9e\u4f8b\u6700\u77ed\u8def\u5f84\u7684 Depth\u3002\u8fd9\u4e9b\u6307\u6807\u653e\u5728\u4e00\u8d77&#xff0c;\u624d\u80fd\u540c\u65f6\u770b\u6e05\u5355\u4e2a\u5bf9\u8c61\u7684\u76f4\u63a5\u5360\u7528\u3001\u5173\u8054\u5360\u7528\u548c\u5b58\u6d3b\u5173\u7cfb\u3002<\/p>\n<\/p>\n<hr \/>\n<h4>2.2 \u4ece\u6ce2\u52a8\u548c\u5206\u914d\u8bb0\u5f55\u5b9a\u4f4d\u5185\u5b58\u6296\u52a8<\/h4>\n<p>\u590d\u5370\u5ba4\u91cc\u6709\u4eba\u4e0d\u65ad\u6253\u5370\u53c8\u4e22\u5f03\u5927\u6279\u8349\u7a3f&#xff0c;\u7eb8\u5f20\u5e93\u5b58\u53ef\u80fd\u6ca1\u6709\u6301\u7eed\u589e\u957f&#xff0c;\u4f46\u8865\u7eb8\u548c\u6e05\u7406\u7684\u52a8\u4f5c\u4f1a\u5f02\u5e38\u9891\u7e41\u3002\u8981\u627e\u5230\u6e90\u5934&#xff0c;\u4e0d\u80fd\u53ea\u770b\u5e93\u5b58\u603b\u91cf&#xff0c;\u8fd8\u8981\u67e5\u54ea\u7c7b\u8349\u7a3f\u6700\u591a\u3001\u662f\u8c01\u5728\u4ec0\u4e48\u65f6\u95f4\u53d1\u8d77\u4e86\u6253\u5370\u3002<\/p>\n<p>\u5bf9\u5e94\u5230 Memory Profiler&#xff0c;\u77ed\u65f6\u95f4\u5185\u9891\u7e41\u521b\u5efa\u5bf9\u8c61\u4f1a\u5e26\u6765\u9891\u7e41 GC\u3002\u5148\u5f55\u5236\u5185\u5b58\u5206\u914d&#xff0c;\u518d\u6309 Allocations \u67e5\u770b\u6570\u91cf\u8f83\u591a\u7684\u5bf9\u8c61&#xff0c;\u9009\u62e9\u5177\u4f53\u5b9e\u4f8b\u5e76\u68c0\u67e5 Allocation Call Stack&#xff0c;\u5c31\u80fd\u628a\u66f2\u7ebf\u4e0a\u7684\u5f02\u5e38\u6d3b\u52a8\u843d\u5230\u5b9e\u9645\u7684\u5bf9\u8c61\u7c7b\u578b\u548c\u521b\u5efa\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<hr \/>\n<h4>2.3 \u6cbf\u5f15\u7528\u94fe\u786e\u8ba4\u5185\u5b58\u6cc4\u6f0f<\/h4>\n<p>\u4e0e\u53cd\u590d\u6253\u5370\u4e0d\u540c&#xff0c;\u4ed3\u5e93\u6cc4\u6f0f\u66f4\u50cf\u4e00\u6279\u672c\u8be5\u6e05\u8d70\u7684\u65e7\u7269\u4ecd\u88ab\u767b\u8bb0\u5728\u957f\u671f\u4fdd\u7ba1\u6e05\u5355\u91cc\u3002\u5e93\u5b58\u4f1a\u4e00\u5c42\u5c42\u589e\u52a0&#xff1b;\u8981\u786e\u8ba4\u95ee\u9898&#xff0c;\u9700\u8981\u67e5\u51fa\u662f\u54ea\u6761\u4fdd\u7ba1\u5173\u7cfb\u8ba9\u65e7\u7269\u4e00\u76f4\u4e0d\u80fd\u79bb\u573a\u3002<\/p>\n<p>\u5728\u5185\u5b58\u6cc4\u6f0f\u5206\u6790\u4e2d&#xff0c;\u9636\u68af\u5f0f\u4e0a\u5347\u4e14\u4e0d\u56de\u843d\u7684\u5185\u5b58\u66f2\u7ebf\u662f\u89c2\u5bdf\u7ebf\u7d22\u3002Heap Dump \u4e2d\u7ecf GC \u540e\u4ecd\u7136\u5b58\u5728\u7684\u591a\u4e2a Activity \u5b9e\u4f8b\u63d0\u4f9b\u8fdb\u4e00\u6b65\u8bc1\u636e&#xff0c;\u800c\u5b9e\u4f8b\u4e0b\u65b9\u7684 Reference \u5219\u7528\u4e8e\u8ffd\u8e2a\u4fdd\u7559\u8fd9\u4e9b\u5b9e\u4f8b\u7684\u5f15\u7528\u94fe&#xff0c;\u4ece\u800c\u5b9a\u4f4d\u5bf9\u8c61\u65e0\u6cd5\u56de\u6536\u7684\u539f\u56e0\u3002<\/p>\n<\/p>\n<hr \/>\n<h3>3. Native Size\u3001Shallow Size\u3001Retained Size \u4e0e Depth<\/h3>\n<p>\u540e\u7eed\u8bf4\u660e Memory Profiler \u548c MAT \u65f6&#xff0c;\u4f1a\u7ecf\u5e38\u51fa\u73b0\u51e0\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u6307\u6807&#xff1a;Shallow Size \u548c Retained Size\u3002\u5728 Memory Profiler \u4e2d\u8fd8\u4f1a\u63d0\u4f9b Native Size \u548c Depth\u3002Google \u5728\u201c\u4f7f\u7528 Android Studio Profiler \u5de5\u5177\u89e3\u6790\u5e94\u7528\u7684\u5185\u5b58\u548c CPU \u4f7f\u7528\u6570\u636e\u201d\u4e2d\u8bb2\u89e3\u4e86\u8fd9\u51e0\u4e2a\u6307\u6807\u7684\u6982\u5ff5&#xff0c;\u4e0b\u9762\u4f1a\u5f15\u7528\u539f\u6587\u8bf4\u660e\u3002Java \u6587\u6863\u4e5f\u5bf9 Shallow Size \u548c Retained Size \u505a\u4e86\u8be6\u7ec6\u8bf4\u660e\u3002<\/p>\n<p>\u5f53\u60a8\u62ff\u5230\u4e00\u6bb5 Heap Dump \u4e4b\u540e&#xff0c;Memory Profiler \u4f1a\u5c55\u793a\u7c7b\u7684\u5217\u8868\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u7c7b&#xff0c;Allocations \u4e00\u5217\u663e\u793a\u5b83\u7684\u5b9e\u4f8b\u6570\u91cf&#xff0c;\u53f3\u8fb9\u4f9d\u6b21\u662f Native Size\u3001Shallow Size \u548c Retained Size&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154237-6a96f26d6b283.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6211\u4eec\u7528\u4e0b\u56fe\u8868\u793a\u67d0\u6bb5 Heap Dump \u8bb0\u5f55\u7684\u5e94\u7528\u5185\u5b58\u72b6\u6001\u3002\u6ce8\u610f\u7ea2\u8272\u8282\u70b9&#xff1a;\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d&#xff0c;\u8be5\u8282\u70b9\u6240\u4ee3\u8868\u7684\u5de5\u7a0b\u5bf9\u8c61\u5f15\u7528\u4e86 Native \u5bf9\u8c61\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0d\u592a\u5e38\u89c1&#xff0c;\u4f46\u5728 Android 8.0 \u4e4b\u540e&#xff0c;\u4f7f\u7528 Bitmap \u4fbf\u53ef\u80fd\u4ea7\u751f\u6b64\u7c7b\u60c5\u666f&#xff0c;\u56e0\u4e3a Bitmap \u4f1a\u628a\u50cf\u7d20\u4fe1\u606f\u5b58\u50a8\u5728\u539f\u751f\u5185\u5b58\u4e2d&#xff0c;\u4ee5\u51cf\u5c11 JVM \u7684\u5185\u5b58\u538b\u529b\u3002<\/p>\n<p>\u5148\u4ece Shallow Size \u8bb2\u8d77\u3002\u8fd9\u5217\u6570\u636e\u5c31\u662f\u5bf9\u8c61\u672c\u8eab\u6d88\u8017\u7684\u5185\u5b58\u5927\u5c0f&#xff0c;\u5373\u7ea2\u8272\u8282\u70b9\u81ea\u8eab\u6240\u5360\u7684\u5185\u5b58&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154237-6a96f26d935e2.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>Native Size \u662f\u7c7b\u5bf9\u8c61\u6240\u5f15\u7528\u7684 Native \u5bf9\u8c61&#xff08;\u84dd\u8272\u8282\u70b9&#xff09;\u6d88\u8017\u7684\u5185\u5b58\u5927\u5c0f&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154237-6a96f26dc7890.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>Retained Size \u7a0d\u590d\u6742\u4e9b&#xff0c;\u5b83\u662f\u4e0b\u56fe\u4e2d\u6240\u6709\u6a59\u8272\u8282\u70b9\u7684\u5927\u5c0f&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154238-6a96f26e0d55b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4e00\u65e6\u5220\u9664\u7ea2\u8272\u8282\u70b9&#xff0c;\u5176\u4f59\u6a59\u8272\u8282\u70b9\u90fd\u5c06\u65e0\u6cd5\u88ab\u8bbf\u95ee&#xff0c;\u8fd9\u65f6\u5b83\u4eec\u5c31\u4f1a\u88ab GC \u56de\u6536\u3002\u4ece\u8fd9\u4e2a\u89d2\u5ea6\u8bb2&#xff0c;\u5b83\u4eec\u7531\u7ea2\u8272\u8282\u70b9\u6301\u6709&#xff0c;\u56e0\u6b64\u88ab\u547d\u540d\u4e3a Retained Size\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u524d\u9762\u6ca1\u6709\u63d0\u5230\u7684\u6570\u636e\u7ef4\u5ea6\u3002\u70b9\u51fb\u67d0\u4e2a\u7c7b\u540d\u540e&#xff0c;\u754c\u9762\u4e2d\u4f1a\u663e\u793a\u8fd9\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u5217\u8868&#xff0c;\u5176\u4e2d\u6709\u4e00\u5217\u65b0\u6570\u636e&#xff1a;Depth\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154238-6a96f26e49154.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>Depth \u662f\u4ece GC Root \u5230\u8fbe\u8fd9\u4e2a\u5b9e\u4f8b\u7684\u6700\u77ed\u8def\u5f84&#xff0c;\u56fe\u4e2d\u7684\u6570\u5b57\u5c31\u662f\u6bcf\u4e2a\u5bf9\u8c61\u7684\u6df1\u5ea6\u3002<\/p>\n<p>\u4e00\u4e2a\u5bf9\u8c61\u79bb GC Root \u8d8a\u8fd1&#xff0c;\u5c31\u8d8a\u6709\u53ef\u80fd\u4e0e GC Root \u901a\u8fc7\u591a\u6761\u8def\u5f84\u76f8\u8fde&#xff0c;\u4e5f\u8d8a\u53ef\u80fd\u5728\u5783\u573e\u56de\u6536\u4e2d\u88ab\u4fdd\u7559\u4e0b\u6765\u3002<\/p>\n<p>\u4ee5\u7ea2\u8272\u8282\u70b9\u4e3a\u4f8b&#xff0c;\u5982\u679c\u4ece\u5176\u5de6\u8fb9\u6765\u7684\u4efb\u610f\u4e00\u4e2a\u5f15\u7528\u88ab\u7834\u574f&#xff0c;\u7ea2\u8272\u8282\u70b9\u5c31\u4f1a\u53d8\u6210\u4e0d\u53ef\u8bbf\u95ee\u72b6\u6001\u5e76\u88ab\u5783\u573e\u56de\u6536\u3002\u5bf9\u4e8e\u53f3\u8fb9\u7684\u84dd\u8272\u8282\u70b9&#xff0c;\u5982\u679c\u5e0c\u671b\u5b83\u88ab\u5783\u573e\u56de\u6536&#xff0c;\u5219\u9700\u8981\u628a\u5de6\u53f3\u4e24\u8fb9\u7684\u8def\u5f84\u90fd\u7834\u574f\u3002<\/p>\n<p>\u5982\u679c\u770b\u5230\u67d0\u4e2a\u5b9e\u4f8b\u7684 Depth \u4e3a 1&#xff0c;\u5c31\u9700\u8981\u683c\u5916\u8b66\u60d5&#xff1a;\u8fd9\u610f\u5473\u7740\u5b83\u76f4\u63a5\u88ab GC Root \u5f15\u7528&#xff0c;\u540c\u65f6\u4e5f\u610f\u5473\u7740\u5b83\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u81ea\u52a8\u56de\u6536\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b Activity&#xff0c;\u5b83\u5b9e\u73b0\u4e86 LocationListener \u63a5\u53e3\u3002\u9ad8\u4eae\u4ee3\u7801 requestLocationUpdates() \u4f1a\u4f7f\u7528\u5f53\u524d Activity \u5b9e\u4f8b\u5411 locationManager \u6ce8\u518c\u76d1\u542c\u3002\u5982\u679c\u5fd8\u8bb0\u6ce8\u9500&#xff0c;\u8fd9\u4e2a Activity \u5c31\u4f1a\u6cc4\u6f0f\u3002\u5b83\u5c06\u4e00\u76f4\u7559\u5728\u5185\u5b58\u91cc&#xff0c;\u56e0\u4e3a\u4f4d\u7f6e\u7ba1\u7406\u5668\u662f\u4e00\u4e2a\u59cb\u7ec8\u5b58\u5728\u7684 GC Root&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154238-6a96f26e66119.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u5728 Memory Profiler \u4e2d\u67e5\u770b\u8fd9\u4e00\u60c5\u51b5\u3002\u70b9\u51fb\u4e00\u4e2a\u5b9e\u4f8b&#xff0c;Memory Profiler \u4f1a\u6253\u5f00\u9762\u677f&#xff0c;\u663e\u793a\u8c01\u6b63\u5728\u5f15\u7528\u8fd9\u4e2a\u5b9e\u4f8b&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154238-6a96f26e8f540.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230&#xff0c;\u4f4d\u7f6e\u7ba1\u7406\u5668\u4e2d\u7684 mListener \u6b63\u5728\u5f15\u7528\u8fd9\u4e2a Activity\u3002\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5f15\u7528\u9762\u677f\u5bfc\u822a\u5230\u5806\u7684\u5f15\u7528\u89c6\u56fe&#xff0c;\u9a8c\u8bc1\u8fd9\u6761\u5f15\u7528\u94fe\u662f\u5426\u7b26\u5408\u9884\u671f&#xff0c;\u5e76\u501f\u6b64\u5224\u65ad\u4ee3\u7801\u4e2d\u662f\u5426\u5b58\u5728\u6cc4\u6f0f\u4ee5\u53ca\u6cc4\u6f0f\u7684\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<hr \/>\n<h3>4. Memory Profiler<\/h3>\n<p>Memory Profiler \u662f Android Studio \u5185\u7f6e\u7684\u5185\u5b58\u5206\u6790\u5de5\u5177&#xff0c;\u9002\u7528\u4e8e\u67e5\u770b\u5b9e\u65f6\u5185\u5b58\u60c5\u51b5\u3002<\/p>\n<\/p>\n<hr \/>\n<h4>4.1 Memory Profiler \u754c\u9762\u8bf4\u660e<\/h4>\n<p>\u5b98\u65b9\u6587\u6863&#xff1a;\u4f7f\u7528 Memory Profiler \u67e5\u770b Java \u5806\u548c\u5185\u5b58\u5206\u914d\u3002<\/p>\n<\/p>\n<hr \/>\n<h4>4.2 Memory Profiler \u67e5\u627e\u5185\u5b58\u6296\u52a8<\/h4>\n<p>\u67e5\u627e\u5185\u5b58\u6296\u52a8\u6bd4\u8f83\u7b80\u5355\u3002\u8fd0\u884c\u4e2d\u7684\u7a0b\u5e8f\u5728 Memory Profiler \u4e2d\u4f1a\u5448\u73b0\u4e3a\u77ed\u65f6\u95f4\u5185\u5185\u5b58\u4e0a\u4e0b\u6ce2\u52a8&#xff0c;\u5e76\u9891\u7e41\u89e6\u53d1 GC \u56de\u6536\u3002<\/p>\n<p>\u5185\u5b58\u6296\u52a8\u6bd4\u8f83\u5e38\u89c1\u7684\u5730\u65b9&#xff1a;<\/p>\n<ul>\n<li>\u81ea\u5b9a\u4e49 View \u7684 onMeasure()\u3001onLayout()\u3001onDraw() \u4e2d\u76f4\u63a5\u4f7f\u7528 new \u521b\u5efa\u5bf9\u8c61<\/li>\n<li>\u5217\u8868&#xff08;\u5982 RecyclerView&#xff09;\u7684 onBindViewHolder() \u4e2d\u76f4\u63a5\u4f7f\u7528 new \u521b\u5efa\u5bf9\u8c61<\/li>\n<li>\u6709\u5faa\u73af\u7684\u4ee3\u7801\u4e2d\u521b\u5efa\u5bf9\u8c61<\/li>\n<\/ul>\n<p>\u7528\u4e00\u4e2a\u7b80\u5355\u6848\u4f8b\u6a21\u62df\u5185\u5b58\u6296\u52a8&#xff1a;<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">MainActivity<\/span> <span class=\"token keyword\">extends<\/span> <span class=\"token class-name\">AppCompatActivity<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;SuppressWarnings<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;HandlerLeak&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">Handler<\/span> mHandler <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Handler<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n        <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">handleMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Message<\/span> msg<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u6a21\u62df\u5185\u5b58\u6296\u52a8<\/span><br \/>\n            <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">100000<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><\/p>\n<p>            mHandler<span class=\"token punctuation\">.<\/span><span class=\"token function\">sendEmptyMessageDelayed<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">30<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n    <span class=\"token keyword\">protected<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">onCreate<\/span><span class=\"token punctuation\">(<\/span><span class=\"token annotation punctuation\">&#064;Nullable<\/span> <span class=\"token class-name\">Bundle<\/span> savedInstanceState<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">super<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">onCreate<\/span><span class=\"token punctuation\">(<\/span>savedInstanceState<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">setContentView<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">R<\/span><span class=\"token punctuation\">.<\/span>layout<span class=\"token punctuation\">.<\/span>activity_main<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token function\">findViewById<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">R<\/span><span class=\"token punctuation\">.<\/span>id<span class=\"token punctuation\">.<\/span>button<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">setOnClickListener<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token class-name\">View<span class=\"token punctuation\">.<\/span>OnClickListener<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n            <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">onClick<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">View<\/span> v<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                mHandler<span class=\"token punctuation\">.<\/span><span class=\"token function\">sendEmptyMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fd9\u4e2a\u6848\u4f8b\u5c31\u662f\u70b9\u51fb\u6309\u94ae\u65f6\u9891\u7e41\u521b\u5efa\u5bf9\u8c61\u3002\u5728\u771f\u673a\u4e0a\u8fd0\u884c\u4e0a\u9762\u7684\u7a0b\u5e8f\u4e5f\u8bb8\u4e0d\u4f1a\u51fa\u73b0\u952f\u9f7f\u72b6\u7684\u5185\u5b58\u6ce2\u52a8&#xff0c;\u4f46\u4f1a\u6709\u975e\u5e38\u9891\u7e41\u7684 GC \u56de\u6536&#xff0c;\u5982\u4e0b\u56fe&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154238-6a96f26eabe3d.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5982\u4f55\u5177\u4f53\u5b9a\u4f4d\u53d1\u751f\u5185\u5b58\u6296\u52a8\u7684\u4f4d\u7f6e&#xff1f;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154239-6a96f26f303d0.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6309\u7167\u4e0a\u56fe\u6b65\u9aa4\u64cd\u4f5c&#xff1a;<\/p>\n<li>\u4f4d\u7f6e\u2460&#xff1a;\u7a0b\u5e8f\u8fd0\u884c\u65f6&#xff0c;\u70b9\u51fb Record \u6309\u94ae\u5f55\u5236\u5185\u5b58\u60c5\u51b5&#xff0c;\u518d\u70b9\u51fb Stop \u505c\u6b62\u5f55\u5236&#xff0c;\u754c\u9762\u4f1a\u663e\u793a\u4e0a\u56fe\u5185\u5bb9\u3002<\/li>\n<li>\u4f4d\u7f6e\u2461&#xff1a;\u70b9\u51fb Allocations&#xff0c;\u6309\u964d\u5e8f\u6216\u5347\u5e8f\u67e5\u770b\u5206\u914d\u5bf9\u8c61\u7684\u6570\u91cf\u3002\u4e00\u822c\u9009\u62e9\u964d\u5e8f&#xff0c;\u4f18\u5148\u67e5\u770b\u6570\u91cf\u6700\u591a\u7684\u5bf9\u8c61\u3002\u4e0a\u56fe\u4e2d\u6570\u91cf\u6700\u591a\u7684\u662f String \u5bf9\u8c61\u3002<\/li>\n<li>\u4f4d\u7f6e\u2462&#xff1a;\u5728 Instance View \u4e2d\u9009\u62e9\u4e00\u4e2a String \u5bf9\u8c61&#xff0c;\u754c\u9762\u4e0b\u65b9\u4f1a\u663e\u793a Allocation Call Stack&#xff0c;\u5176\u4e2d\u5305\u542b\u8be5\u5bf9\u8c61\u7684\u8c03\u7528\u6808\u4f4d\u7f6e\u3002<\/li>\n<li>\u4f4d\u7f6e\u2463&#xff1a;\u4ece Allocation Call Stack \u53ef\u4ee5\u770b\u5230&#xff0c;String \u5bf9\u8c61\u662f\u5728 MainActivity \u7b2c 18 \u884c\u7684 handleMessage() \u4e2d\u521b\u5efa\u7684&#xff0c;\u7531\u6b64\u5b9a\u4f4d\u5230\u5185\u5b58\u6296\u52a8\u7684\u4f4d\u7f6e\u3002<\/li>\n<p>\u4e0a\u8ff0\u64cd\u4f5c\u8fd8\u6709\u4e00\u4e9b\u5c0f\u6280\u5de7&#xff1a;<\/p>\n<ul>\n<li>\u6267\u884c\u4f4d\u7f6e\u2460\u7684\u64cd\u4f5c\u524d&#xff0c;\u4e3a\u6392\u9664\u5e72\u6270&#xff0c;\u4e00\u822c\u5148\u624b\u52a8\u6267\u884c GC&#xff0c;\u518d\u5f55\u5236\u53d8\u5316\u7684\u5185\u5b58\u3002\u5728 Android 8.0 \u4ee5\u4e0a\u7684\u8bbe\u5907\u4e2d&#xff0c;\u53ef\u4ee5\u5b9e\u65f6\u62d6\u52a8 Memory Profiler&#xff0c;\u9009\u62e9\u8981\u67e5\u770b\u7684\u5185\u5b58\u6ce2\u52a8\u8303\u56f4\u3002<\/li>\n<li>\u4f4d\u7f6e\u2461\u7684\u793a\u4f8b\u76f4\u63a5\u4f7f\u7528 Arrange by class \u67e5\u770b&#xff0c;\u4f46\u5728\u5b9e\u9645\u9879\u76ee\u4e2d&#xff0c;\u66f4\u591a\u4f1a\u9009\u62e9 Arrange by package&#xff0c;\u67e5\u770b\u81ea\u5df1\u9879\u76ee\u5305\u540d\u4e0b\u7684\u7c7b\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>4.3 Memory Profiler \u67e5\u627e\u5185\u5b58\u6cc4\u6f0f<\/h4>\n<p>\u4e0a\u9762\u8bb2\u5230&#xff0c;\u5185\u5b58\u6cc4\u6f0f\u4f1a\u4f34\u968f\u5185\u5b58\u6296\u52a8\u3002\u53d1\u751f\u5185\u5b58\u6cc4\u6f0f\u65f6&#xff0c;\u53ef\u7528\u5185\u5b58\u4e0d\u65ad\u51cf\u5c11&#xff1b;\u7cfb\u7edf\u9700\u8981\u5185\u5b58\u5374\u53d1\u73b0\u5185\u5b58\u4e0d\u8db3\u65f6\u5c31\u4f1a\u6267\u884c GC&#xff0c;\u56e0\u6b64\u4ea7\u751f\u5185\u5b58\u6296\u52a8\u3002<\/p>\n<p>\u53d1\u751f\u5185\u5b58\u6cc4\u6f0f\u65f6&#xff0c;Memory Profiler \u4f1a\u5448\u73b0\u7c7b\u4f3c\u9636\u68af\u5f0f\u7684\u5185\u5b58\u4e0a\u5347\u8d8b\u52bf&#xff0c;\u800c\u4e14\u5185\u5b58\u6ca1\u6709\u964d\u4e0b\u6765&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154239-6a96f26fc94a6.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4e0a\u56fe\u7684\u5185\u5b58\u6cc4\u6f0f\u6bd4\u8f83\u660e\u663e\u3002\u5b9e\u9645\u9879\u76ee\u5f00\u53d1\u4e2d\u51fa\u73b0\u5185\u5b58\u6cc4\u6f0f\u65f6&#xff0c;\u8d8b\u52bf\u53ef\u80fd\u5e76\u4e0d\u660e\u663e&#xff0c;\u9700\u8981\u8fd0\u884c\u8f83\u957f\u65f6\u95f4\u624d\u80fd\u53d1\u73b0\u5185\u5b58\u5728\u7f13\u6162\u4e0a\u5347\u3002\u8fd9\u65f6\u5c31\u9700\u8981 Dump Heap \u5e2e\u52a9\u5b9a\u4f4d\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u4f7f\u7528 Handler \u5185\u5b58\u6cc4\u6f0f\u6848\u4f8b&#xff0c;\u7b80\u5355\u8bf4\u660e\u5982\u4f55\u4f7f\u7528 Memory Profiler \u5206\u6790\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">HandlerLeakActivity<\/span> <span class=\"token keyword\">extends<\/span> <span class=\"token class-name\">AppCompatActivity<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">final<\/span> <span class=\"token class-name\">String<\/span> <span class=\"token constant\">TAG<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">HandlerLeakActivity<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">getSimpleName<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">Handler<\/span> handler <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Handler<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n        <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">handleMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Message<\/span> msg<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>msg<span class=\"token punctuation\">.<\/span>what <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token class-name\">Log<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">i<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">TAG<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;handler receive msg&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n    <span class=\"token keyword\">protected<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">onCreate<\/span><span class=\"token punctuation\">(<\/span><span class=\"token annotation punctuation\">&#064;Nullable<\/span> <span class=\"token class-name\">Bundle<\/span> savedInstanceState<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">super<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">onCreate<\/span><span class=\"token punctuation\">(<\/span>savedInstanceState<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        handler<span class=\"token punctuation\">.<\/span><span class=\"token function\">sendEmptyMessageDelayed<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">10<\/span> <span class=\"token operator\">*<\/span> <span class=\"token number\">1000<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5f88\u7b80\u5355&#xff1a;\u542f\u52a8 App \u540e&#xff0c;\u6bcf\u6b21\u8fdb\u5165 HandlerLeakActivity \u90fd\u4f7f\u7528 Handler \u5ef6\u8fdf 10 \u79d2\u53d1\u9001\u6d88\u606f&#xff1b;\u5728 10 \u79d2\u5185\u9000\u51fa\u754c\u9762&#xff0c;\u5e76\u4e0d\u65ad\u91cd\u590d\u8be5\u64cd\u4f5c\u3002<\/p>\n<li>\u91cd\u590d\u591a\u6b21\u53ef\u80fd\u5f15\u53d1\u5185\u5b58\u6cc4\u6f0f\u7684\u64cd\u4f5c&#xff0c;\u4f7f\u7528 Memory Profiler \u6267\u884c\u5806\u8f6c\u50a8&#xff0c;\u751f\u6210 HPROF \u6587\u4ef6\u3002\u5efa\u8bae\u64cd\u4f5c\u524d\u5148\u6267\u884c GC&#xff0c;\u4ee5\u6392\u9664\u5e72\u6270&#xff1a;<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154240-6a96f2701d015.gif\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/li>\n<li>\u5728 Memory Profiler \u4e2d\u67e5\u770b\u5806\u8f6c\u50a8\u751f\u6210\u7684 HPROF \u6587\u4ef6&#xff1a;<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154240-6a96f2707b149.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/li>\n<p>\u53ef\u4ee5\u53d1\u73b0&#xff0c;\u624b\u52a8\u6267\u884c GC \u540e&#xff0c;Allocations \u4e2d\u4ecd\u663e\u793a 5 \u4e2a HandlerLeakActivity&#xff0c;\u5806\u8f6c\u50a8\u7684 Instance View \u4e0b\u4e5f\u4ecd\u663e\u793a\u591a\u4e2a Activity \u5b9e\u4f8b&#xff0c;\u8bf4\u660e\u5df2\u7ecf\u53d1\u751f\u5185\u5b58\u6cc4\u6f0f\u3002\u8981\u8fdb\u4e00\u6b65\u5b9a\u4f4d\u6cc4\u6f0f&#xff0c;\u53ef\u4ee5\u5728 Instance View \u4e2d\u70b9\u51fb\u53d1\u751f\u6cc4\u6f0f\u7684\u5b9e\u4f8b\u7c7b\u5bf9\u8c61&#xff1b;Instance View \u4e0b\u65b9\u7684 Reference \u4f1a\u663e\u793a\u5177\u4f53\u7684\u5f15\u7528\u94fe\u3002<\/p>\n<p>\u65b0\u7248\u672c\u7684 Memory Profiler \u63d0\u4f9b\u4e86 Activity\/Fragment Leaks \u590d\u9009\u6846&#xff0c;\u9009\u4e2d\u540e\u53ef\u4ee5\u76f4\u63a5\u627e\u5230\u53ef\u80fd\u53d1\u751f\u5185\u5b58\u6cc4\u6f0f\u7684\u4f4d\u7f6e&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154241-6a96f2711d3c9.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android Memory Profiler&#xff1a;\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d Android Memory Profiler&#xff1a;\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d1. \u9605\u8bfb\u524d\u95ee\u9898\u5361&#xff1a;Memory Profiler \u5185\u5b58\u5206\u6790 1.1 \u9605\u8bfb\u524d\u5148\u770b\u8fd9\u51e0\u4e2a\u95ee\u98981.2 \u8bfb\u5b8c\u540e\u5b8c\u6210\u8fd9 3 \u9053\u9ad8\u9891\u95ee\u98981.3 \u81ea\u68c0\u6e05\u5355 2. \u524d\u8a00 2.1 \u770b\u6e05\u4e00\u4e2a\u5bf9\u8c61\u5360\u7528\u548c\u7275\u8fde\u7684\u5185\u5b582.2 \u4ece\u6ce2\u52a8\u548c\u5206\u914d\u8bb0\u5f55\u5b9a\u4f4d\u5185\u5b58\u6296\u52a82.3 \u6cbf\u5f15\u7528\u94fe\u786e\u8ba4\u5185\u5b58\u6cc4\u6f0f 3. Native S<\/p>\n","protected":false},"author":2,"featured_media":99103,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11339,11340,11338,84,56],"topic":[],"class_list":["post-99116","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-memory-profiler","tag-11340","tag-11338","tag-android","tag-56"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android Memory Profiler\uff1a\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/99116.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Memory Profiler\uff1a\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Android Memory Profiler&#xff1a;\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d Android Memory Profiler&#xff1a;\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d1. \u9605\u8bfb\u524d\u95ee\u9898\u5361&#xff1a;Memory Profiler \u5185\u5b58\u5206\u6790 1.1 \u9605\u8bfb\u524d\u5148\u770b\u8fd9\u51e0\u4e2a\u95ee\u98981.2 \u8bfb\u5b8c\u540e\u5b8c\u6210\u8fd9 3 \u9053\u9ad8\u9891\u95ee\u98981.3 \u81ea\u68c0\u6e05\u5355 2. \u524d\u8a00 2.1 \u770b\u6e05\u4e00\u4e2a\u5bf9\u8c61\u5360\u7528\u548c\u7275\u8fde\u7684\u5185\u5b582.2 \u4ece\u6ce2\u52a8\u548c\u5206\u914d\u8bb0\u5f55\u5b9a\u4f4d\u5185\u5b58\u6296\u52a82.3 \u6cbf\u5f15\u7528\u94fe\u786e\u8ba4\u5185\u5b58\u6cc4\u6f0f 3. Native S\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/99116.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-01T15:42:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154237-6a96f26d6b283.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/99116.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/99116.html\",\"name\":\"Android Memory Profiler\uff1a\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-01T15:42:42+00:00\",\"dateModified\":\"2026-09-01T15:42:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/99116.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/99116.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/99116.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android Memory Profiler\uff1a\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Memory Profiler\uff1a\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/99116.html","og_locale":"zh_CN","og_type":"article","og_title":"Android Memory Profiler\uff1a\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Android Memory Profiler&#xff1a;\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d Android Memory Profiler&#xff1a;\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d1. \u9605\u8bfb\u524d\u95ee\u9898\u5361&#xff1a;Memory Profiler \u5185\u5b58\u5206\u6790 1.1 \u9605\u8bfb\u524d\u5148\u770b\u8fd9\u51e0\u4e2a\u95ee\u98981.2 \u8bfb\u5b8c\u540e\u5b8c\u6210\u8fd9 3 \u9053\u9ad8\u9891\u95ee\u98981.3 \u81ea\u68c0\u6e05\u5355 2. \u524d\u8a00 2.1 \u770b\u6e05\u4e00\u4e2a\u5bf9\u8c61\u5360\u7528\u548c\u7275\u8fde\u7684\u5185\u5b582.2 \u4ece\u6ce2\u52a8\u548c\u5206\u914d\u8bb0\u5f55\u5b9a\u4f4d\u5185\u5b58\u6296\u52a82.3 \u6cbf\u5f15\u7528\u94fe\u786e\u8ba4\u5185\u5b58\u6cc4\u6f0f 3. Native S","og_url":"https:\/\/www.wsisp.com\/helps\/99116.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-01T15:42:42+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260901154237-6a96f26d6b283.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/99116.html","url":"https:\/\/www.wsisp.com\/helps\/99116.html","name":"Android Memory Profiler\uff1a\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-01T15:42:42+00:00","dateModified":"2026-09-01T15:42:42+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/99116.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/99116.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/99116.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Android Memory Profiler\uff1a\u5806\u5185\u5b58\u6307\u6807\u3001\u5185\u5b58\u6296\u52a8\u4e0e\u6cc4\u6f0f\u5b9a\u4f4d"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/99116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=99116"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/99116\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/99103"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=99116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=99116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=99116"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=99116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}