\u5185\u5b58\u65e0\u6cd5\u5220\u9664<\/strong><\/div>\n\u53e6\u4e00\u7c7b\u6bd4\u8f83\u6709\u8da3\u7684\u5185\u5b58\u6cc4\u6f0f\u662f\u8bf4\u4f60\u7533\u8bf7\u4e86\u4e00\u4e9b\u5185\u5b58\uff0c\u4f46\u6700\u7ec8\u5374\u6ca1\u6709\u4ec0\u4e48\u6307\u5411\u5b83\u4eec\uff1a<\/p>\n
\r\nvoid memory_leak() { \r\n char* mem = (char*)malloc(1024); \r\n \/\/ just return \r\n} <\/pre>\n\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\u6211\u4eec\u7533\u8bf7\u4e861k\u5185\u5b58\uff0c\u7136\u800c\u5f53memory_leak\u51fd\u6570\u8fd4\u56de\u540e\u4f60\u5c31\u518d\u4e5f\u4e0d\u77e5\u9053\u8fd9\u6bb5\u5185\u5b58\u5230\u5e95\u5728\u54ea\u91cc\u4e86!<\/p>\n
\u7528\u505c\u8f66\u573a\u7684\u793a\u4f8b\u6765\u8bf4\u5c31\u662f\u6709\u4e9b\u53f8\u673a\u592a\u8fc7\u571f\u8c6a\uff0c\u5bb6\u91cc\u7684\u8f66\u592a\u591a\u4ee5\u81f3\u4e8e\u628a\u5c06\u8f66\u653e\u5728\u505c\u8f66\u573a\u8fd9\u4ef6\u4e8b\u5fd8\u6389\u4e86\uff0c\u5bfc\u81f4\u8fd9\u4e9b\u8f66\u6839\u672c\u5c31\u4e0d\u4f1a\u6709\u4eba\u518d\u5f00\u8d70\uff0c\u56e0\u6b64\u767d\u767d\u6d6a\u8d39\u505c\u8f66\u4f4d\uff0c\u5e76\u5bfc\u81f4\u53ef\u7528\u8f66\u4f4d\u8d8a\u6765\u8d8a\u5c11\uff0c\u800c\u5bf9\u4e8e\u7f16\u7a0b\u6765\u8bf4\u5c31\u662f\u7c97\u5fc3\u5927\u610f\u7684\u7a0b\u5e8f\u5458\u7533\u8bf7\u4e86\u4e00\u4e9b\u5185\u5b58\u540e\u6700\u7ec8\u201c\u5fd8\u6389\u201d\u4e86\uff0c\u518d\u4e5f\u4e0d\u4f1a\u6709\u4ec0\u4e48\u4e1c\u897f(\u53d8\u91cf\/\u6307\u9488)\u6307\u5411\u8fd9\u4e9b\u5185\u5b58\uff0c\u56e0\u6b64\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4f60\u6ca1\u6709\u529e\u6cd5\u518d\u627e\u5230\u8fd9\u4e9b\u5185\u5b58\u5e76\u5c06\u5176\u5220\u9664\u3002<\/p>\n
\u5185\u5b58\u788e\u7247
\n\u8fd9\u4e5f\u7b97\u7684\u4e0a\u662f\u4e00\u7c7b\u7279\u6b8a\u7684\u5185\u5b58\u6cc4\u6f0f\uff0c\u7528\u505c\u8f66\u573a\u7684\u4f8b\u5b50\u6765\u8bf4\u5c31\u662f\u4e24\u4e2a\u505c\u8f66\u4f4d\u4e2d\u95f4\u505c\u9760\u4e86\u4e00\u8f86\u5c0f\u578b\u8001\u5e74\u4ee3\u6b65\u8f66\uff0c\u5bfc\u81f4\u5c3d\u7ba1\u8fd9\u4e24\u4e2a\u505c\u8f66\u4f4d\u5269\u4f59\u7684\u7a7a\u95f4\u8db3\u591f\u5927\u4f46\u53c8\u6070\u597d\u90fd\u6ca1\u6709\u529e\u6cd5\u518d\u505c\u9760\u4e00\u8f86\u5c0f\u6c7d\u8f66\u3002<\/p>\n
\u5047\u5b9a\u6211\u4eec\u7cfb\u7edf\u4e2d\u5b9d\u8d35\u7684\u5185\u5b58\u5927\u5c0f\u53ea\u67098\u5b57\u8282\uff0c\u5176\u4e2d\u6709\u4e24\u4e2a\u5b57\u8282\u5df2\u7ecf\u5206\u914d\u51fa\u53bb\u4e86\uff0c\u5c31\u50cf\u8fd9\u6837\uff1a<\/p>\n
<\/p>\n
\u73b0\u5728\uff0c\u7cfb\u7edf\u4e2d\u7a7a\u95f2\u7684\u5185\u5b58\u662f6\u5b57\u8282\uff0c\u4e0b\u4e00\u6b21\u7684\u5185\u5b58\u7533\u8bf7\u9700\u8981\u5206\u914d5\u5b57\u8282\uff0c\u7cdf\u7cd5\uff0c\u6211\u4eec\u5df2\u7ecf\u6ca1\u6709\u529e\u6cd5\u518d\u627e\u5230\u8fde\u7eed\u76845\u4e2a\u5b57\u8282\u5927\u5c0f\u7684\u5185\u5b58\u7a7a\u95f4\u4e86\uff0c\u5c3d\u7ba1\u5168\u90e8\u7a7a\u95f4\u7684\u5185\u5b58\u8fd8\u67096\u5b57\u8282\uff0c\u8fd9\u5c31\u662f\u6240\u8c13\u7684\u5185\u5b58\u788e\u7247\u95ee\u9898\u3002<\/p>\n
\u800c\u5bf9\u4e8e\u5185\u5b58\u5206\u914d\u5668\u6765\u8bf4\u5982\u679c\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u90a3\u4e48\u5c06\u4e0d\u5f97\u4e0d\u501f\u52a9\u64cd\u4f5c\u7cfb\u7edf\u7684\u5e2e\u52a9\u6765\u6269\u5927\u5806\u533a\uff0c\u56e0\u6b64\u770b\u8d77\u6765\u6211\u4eec\u7684\u7a0b\u5e8f\u5360\u636e\u7684\u5185\u5b58\u8d8a\u6765\u8d8a\u591a\uff0c\u5c3d\u7ba1\u5b9e\u9645\u4e0a\u7a0b\u5e8f\u53ef\u80fd\u5e76\u4e0d\u9700\u8981\u90a3\u4e48\u591a\u5185\u5b58\uff0c\u4ec5\u4ec5\u662f\u56e0\u4e3a\u5185\u5b58\u788e\u7247\u7684\u539f\u56e0\u5bfc\u81f4\u4e00\u90e8\u5206\u5185\u5b58\u65e0\u6cd5\u88ab\u518d\u6b21\u88ab\u5229\u7528\u8d77\u6765\u3002<\/p>\n
\u7136\u800c\u5bf9\u4e8e\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u5c24\u5176\u5177\u5907\u865a\u62df\u5185\u5b58\u80fd\u529b\u7684\u7cfb\u7edf\u6765\u8bf4\uff0c\u5185\u5b58\u788e\u7247\u95ee\u9898\u901a\u5e38\u53ef\u80fd\u5e76\u4e0d\u4f1a\u548c\u6211\u4eec\u60f3\u8c61\u7684\u90a3\u6837\u4e25\u91cd\uff0c\u539f\u56e0\u5c31\u5728\u4e8e\u5206\u914d\u7684\u5185\u5b58\u53ea\u9700\u8981\u5728\u865a\u62df\u5730\u5740\u7a7a\u95f4\u4e0a\u8fde\u7eed\u800c\u4e0d\u5fc5\u5728\u7269\u7406\u5185\u5b58\u4e0a\u4e5f\u8fde\u7eed\uff0c\u5047\u5b9a\u6211\u4eec\u5728\u865a\u62df\u5185\u5b58\u5730\u5740\u7a7a\u95f4\u9700\u8981\u5b58\u653e\u201caabbccdd\u201d\u8fd9\u6837\u7684\u5b57\u7b26\u4e32\uff0c\u5728\u865a\u62df\u5730\u5740\u7a7a\u95f4\u4e0a\u770b\u8fd9\u662f\u8fde\u7eed\u7684\u5c31\u50cf\u8fd9\u6837\uff1a<\/p>\n
<\/p>\n
\u4f46\u5728\u7269\u7406\u5185\u5b58\u4e0a\u53ef\u80fd\u662f\u8fd9\u6837\u5b58\u653e\u7684\uff1a<\/p>\n
<\/p>\n
\u53ef\u4ee5\u770b\u5230\uff0c\u5229\u7528\u865a\u62df\u5185\u5b58\u6211\u4eec\u53ef\u4ee5\u66f4\u52a0\u5145\u5206\u7075\u6d3b\u7684\u5229\u7528\u201c\u8fb9\u8fb9\u89d2\u89d2\u201d\u7684\u7269\u7406\u5185\u5b58\uff0c\u4ece\u800c\u51cf\u5c11\u5185\u5b58\u788e\u7247\u5e26\u6765\u7684\u5f71\u54cd\u3002<\/p>\n
\u5173\u4e8e\u865a\u62df\u5185\u5b58\u66f4\u8be6\u7ec6\u7684\u8bb2\u89e3\u4f60\u53ef\u4ee5\u53c2\u8003\u300a\u6df1\u5165\u7406\u89e3\u64cd\u4f5c\u7cfb\u7edf\u300b\u865a\u62df\u5185\u5b58\u4e00\u7ae0\uff0c\u5173\u4e8e\u516c\u4f17\u53f7\u201c\u7801\u519c\u7684\u8352\u5c9b\u6c42\u751f\u201d\u5e76\u56de\u590d\u201c\u64cd\u4f5c\u7cfb\u7edf\u201d\u5373\u53ef\u3002<\/p>\n
\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u9700\u8981\u91cd\u590d\u7533\u8bf7\u5f88\u591a\u5bf9\u8c61\/\u6570\u636e\/\u7ed3\u6784\u4f53\uff0c\u5e76\u5728\u6700\u540e\u4e00\u6b21\u6027\u5168\u90e8\u91ca\u653e\uff0c\u90a3\u4e48\u5185\u5b58\u6c60\u662f\u4e00\u4e2a\u907f\u514d\u5185\u5b58\u788e\u7247\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u539f\u7406\u5728\u4e8e\u5c3d\u7ba1\u4ece\u5185\u5b58\u6c60\u7684\u89d2\u5ea6\u770b\u4f1a\u6709\u788e\u7247\uff0c\u4f46\u5f53\u6211\u4eec\u4ee5\u5185\u5b58\u6c60\u5927\u5c0f\u4e3a\u5355\u4f4d\u4ece\u5806\u533a\u4e2d\u7533\u8bf7\u91ca\u653e\u5185\u5b58\u65f6\uff0c\u8fd9\u79cd\u788e\u7247\u5c06\u4e0d\u590d\u5b58\u5728\u3002<\/p>\n
\u5173\u4e8e\u5185\u5b58\u6c60\u4f60\u53ef\u4ee5\u53c2\u8003\u8fd9\u7bc7\u300a\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u5185\u5b58\u6c60\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u300b\u3002<\/p>\n
\u5185\u5b58\u6cc4\u6f0f\u5e26\u6765\u7684\u95ee\u9898<\/strong><\/div>\n\u5728\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u9664\u975e\u4f60\u7684\u7a0b\u5e8f\u8fd0\u884c\u65f6\u95f4\u8db3\u591f\u957f\u6216\u8005\u7533\u8bf7\u7684\u5185\u5b58\u8db3\u591f\u5feb\u8db3\u591f\u591a\u5426\u5219\u5185\u5b58\u6cc4\u6f0f\u53ef\u80fd\u5e76\u4e0d\u662f\u4ec0\u4e48\u5927\u95ee\u9898\uff0c\u4f60\u751a\u81f3\u53ef\u80fd\u90fd\u5bdf\u89c9\u4e0d\u51fa\u6765\u6709\u5185\u5b58\u6cc4\u6f0f\uff0c\u56e0\u4e3a\u5f53\u8fdb\u7a0b\u8fd0\u884c\u7ed3\u675f\u540e\u5176\u5360\u636e\u7684\u5185\u5b58\u4f1a\u88ab\u64cd\u4f5c\u7cfb\u7edf\u6536\u56de\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4f60\u53ef\u80fd\u4e0d\u5fc5\u8fc7\u4e8e\u5173\u5fc3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f46\u5bf9\u4e8e\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u670d\u52a1\u5668\u7aef\u7a0b\u5e8f\u3001\u6570\u636e\u5e93\u7a0b\u5e8f\u3001\u64cd\u4f5c\u7cfb\u7edf\u7b49\uff0c\u5185\u5b58\u6cc4\u6f0f\u5c31\u5c5e\u4e8e\u6bd4\u8f83\u4e25\u91cd\u7684\u95ee\u9898\u4e86\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u7a0b\u5e8f\u5fc5\u987b\u65f6\u523b\u5728\u7ebf\uff0c\u4efb\u4f55\u5fae\u5c0f\u7684\u5185\u5b58\u6cc4\u6f0f\u5728\u65f6\u95f4\u7684\u52a0\u6301\u4e0b\u90fd\u4f1a\u975e\u5e38\u660e\u663e\u3002<\/p>\n
\u5185\u5b58\u6301\u7eed\u6cc4\u6f0f\u4f1a\u53d1\u751f\u4ec0\u4e48?<\/strong><\/div>\n\u5982\u679c\u5185\u5b58\u6301\u7eed\u6cc4\u6f0f\u90a3\u4e48\u4f60\u7684\u7535\u8111\u53ef\u80fd\u4f1a\u7206\u70b8\u3002\u3002\u3002\u8fd9\u3002\u3002\u3002\u5f53\u7136\u662f\u4e0d\u53ef\u80fd\u7684\u3002<\/p>\n
\u4f60\u7684\u7cfb\u7edf\u4f1a\u6162\u5230\u70b8\u662f\u6709\u53ef\u80fd\u7684\u3002<\/p>\n
\u5185\u5b58\u7684\u7533\u8bf7\u901f\u5ea6\u4f1a\u5bf9\u7cfb\u7edf\u6027\u80fd\u4ea7\u751f\u5f88\u5927\u7684\u5f71\u54cd\uff0c\u5f53\u7cfb\u7edf\u5185\u5b58\u4e0d\u8db3\u65f6\uff0c\u5185\u5b58\u5206\u914d\u5668\u627e\u5230\u4e00\u5757\u6ee1\u8db3\u8981\u6c42\u7684\u7a7a\u95f2\u5185\u5b58\u5757\u5c06\u66f4\u52a0\u56f0\u96be\u8017\u65f6\u66f4\u591a\uff0c\u5f53\u7a0b\u5e8f\u6d88\u8017\u7684\u5185\u5b58\u8d85\u8fc7\u7269\u7406\u5185\u5b58\u5927\u5c0f\u65f6\u865a\u62df\u5185\u5b58\u7cfb\u7edf(\u5982\u679c\u6709\u7684\u8bdd)\u5f00\u59cb\u53d1\u6325\u4f5c\u7528\uff0c\u5c06\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u4e2d\u4e0d\u5e38\u7528\u7684\u4e00\u90e8\u5206swap\u51fa\u53bb\uff0c\u6b64\u65f6\u7cfb\u7edf\u6027\u80fd\u5c06\u5feb\u901f\u4e0b\u964d\uff0c\u8868\u73b0\u51fa\u6765\u7684\u5c31\u662f\u7a0b\u5e8f\u5458\u8fd0\u884c\u53d8\u6162\u3001\u5361\u987f\u3002<\/p>\n
\u5f53\u7136\uff0c\u6839\u636e\u7cfb\u7edf\u914d\u7f6e\uff0c\u50cfLinux\u7cfb\u7edf\uff0c\u53ef\u80fd\u4f1a\u5c06\u6d88\u8017\u5185\u5b58\u5f88\u591a\u7684\u8fdb\u7a0bkill\u6389\uff0c\u8fd9\u5c31\u662fOut of Memory killer\uff0c\u7b80\u79f0oom killer\u3002<\/p>\n
\u5185\u5b58\u6cc4\u6f0f\u68c0\u6d4b\u5de5\u5177<\/strong><\/div>\n\u4e0d\u50cf\u7a0b\u5e8f\u5d29\u6e83Core dump\uff0c\u8fd9\u7c7b\u95ee\u9898\u901a\u8fc7debug\u901a\u5e38\u80fd\u83b7\u53d6\u4e00\u4e9b\u7ebf\u7d22\uff0c\u4f46\u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\u5c31\u6ca1\u90a3\u4e48\u76f4\u63a5\u4e86\uff0c\u5c24\u5176\u5bf9\u4e8eC\/C++\u7a0b\u5e8f\u6765\u8bf4\uff0c\u8fd9\u65f6\u6211\u4eec\u5c06\u4e0d\u5f97\u4e0d\u501f\u52a9\u5fc5\u8981\u7684\u5de5\u5177\u3002<\/p>\n
\u90a3\u4e48\u6211\u4eec\u8be5\u5229\u7528\u4ec0\u4e48\u7684\u5de5\u5177\u6765\u89e3\u51b3\u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\u5462?\u4e0b\u4e00\u7bc7\u6587\u7ae0\u5c06\u7ed9\u4f60\u7b54\u6848\u3002<\/p>\n
\u8fd9\u4e2a\u516c\u4f17\u53f7\u91cc\u6240\u6709\u7684\u6587\u7ae0\u90fd\u5df2\u7ecf\u6c47\u603b\u5728\u4e86Github\u4e0a\uff0c\u5730\u5740https:\/\/github.com\/xfenglu\/everycodershouldknow \uff0c\u4f60\u4e5f\u53ef\u4ee5\u70b9\u51fb\u5de6\u4e0b\u65b9\u201c\u9605\u8bfb\u539f\u6587\u201d\u76f4\u8fbe\uff0c\u6b22\u8fce\u8bbf\u95ee\uff0c\u6c42star\uff0c\u54c8\u54c8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5927\u5bb6\u597d\uff0c\u6211\u662f\u5c0f\u98ce\u54e5\uff0c\u4eca\u5929\u548c\u5927\u5bb6\u804a\u4e00\u804a\u5185\u5b58\u6cc4\u6f0f\u8fd9\u4e2a\u8bdd\u9898\u3002 \u6211\u4e4b\u524d\u5199\u8fc7\u597d\u51e0\u7bc7\u5173\u4e8e\u5185\u5b58\u7684\u6587\u7ae0\uff0c\u5728\u8fd9\u4e9b\u6587\u7ae0\u8bb2\u5230\u5185\u5b58\u7533\u8bf7 […]<\/p>\n","protected":false},"author":317,"featured_media":213305,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-233811","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/233811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/317"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=233811"}],"version-history":[{"count":3,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/233811\/revisions"}],"predecessor-version":[{"id":234137,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/233811\/revisions\/234137"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/213305"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=233811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=233811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=233811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}