{"id":213303,"date":"2021-03-20T10:14:43","date_gmt":"2021-03-20T02:14:43","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=213303"},"modified":"2021-03-08T08:15:49","modified_gmt":"2021-03-08T00:15:49","slug":"java-memory-overflow","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/java-memory-overflow.html","title":{"rendered":"Java\u5185\u5b58\u6ea2\u51fa"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u5185\u5b58\u6ea2\u51fa\u662f\u6307\u5e94\u7528\u7cfb\u7edf\u4e2d\u5b58\u5728\u65e0\u6cd5\u56de\u6536\u7684\u5185\u5b58\u6216\u4f7f\u7528\u7684\u5185\u5b58\u8fc7\u591a\uff0c\u6700\u7ec8\u4f7f\u5f97\u7a0b\u5e8f\u8fd0\u884c\u8981\u7528\u5230\u7684\u5185\u5b58\u5927\u4e8e\u865a\u62df\u673a\u80fd\u63d0\u4f9b\u7684\u6700\u5927\u5185\u5b58\u3002\u8fd9\u7bc7\u6587\u7ae0\u6574\u7406\u81ea\u300a\u6df1\u5165\u7406\u89e3java\u865a\u62df\u673a\u300b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u4e00\u3001\u5185\u5b58\u6ea2\u51fa\u539f\u56e0<\/strong><\/div>\n \u5185\u5b58\u6ea2\u51fa\u5c31\u662f\u5185\u5b58\u4e0d\u591f\uff0c\u5f15\u8d77\u5185\u5b58\u6ea2\u51fa\u7684\u539f\u56e0\u6709\u5f88\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a<\/p>\n
\u5f53\u7136\u5b9e\u9645\u60c5\u51b5\u4e2d\u5185\u5b58\u6ea2\u51fa\u7684\u539f\u56e0\u5c31\u592a\u591a\u4e86\u3002\u4e0b\u9762\u6211\u4eec\u5c31\u5bf9\u8fd9\u4e9b\u539f\u56e0\u5206\u7c7b\u4e00\u4e0b\uff1a<\/p>\n \u4ee5\u4e0a\u7684\u56fe\u662f\u57fa\u4e8ejava7\u6765\u53d9\u8ff0\u7684\uff0c\u4ece\u4e0a\u9762\u8fd9\u5f20\u56fe\u6211\u4eec\u80fd\u591f\u5f97\u5230\u5982\u4e0b\u4fe1\u606f\uff1ajava\u865a\u62df\u673a\u628a\u5185\u5b58\u5206\u4e3a5\u4e2a\u6a21\u5757\u3002<\/p>\n
\u7a0b\u5e8f\u8ba1\u6570\u5668\u662f\u7ebf\u7a0b\u79c1\u6709\u7684\uff0c\u4e3b\u8981\u7684\u4f5c\u7528\u662f\u901a\u8fc7\u6539\u53d8\u8fd9\u4e2a\u8ba1\u6570\u5668\u7684\u503c\u6765\u9009\u53d6\u4e0b\u4e00\u6761\u9700\u8981\u6267\u884c\u7684\u5b57\u8282\u7801\u6307\u4ee4\u3002\u65e2\u7136\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u6709\u4e00\u4e2a\uff0c\u90a3\u4e48\u8fd9\u4e9b\u7ebf\u7a0b\u7684\u8ba1\u6570\u5668\u662f\u4e92\u4e0d\u5f71\u54cd\u7684\u3002\u4e5f\u4e0d\u4f1a\u629b\u51fa\u4efb\u4f55\u5f02\u5e38\u3002<\/p>\n
\u865a\u62df\u673a\u6808\u63cf\u8ff0\u7684\u662fjava\u65b9\u6cd5\u6267\u884c\u7684\u5185\u5b58\u6a21\u578b\uff0c\u6bcf\u4e2a\u65b9\u6cd5\u5728\u6267\u884c\u7684\u65f6\u5019\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u6808\u5e27\u7528\u4e8e\u5b58\u50a8\u5c40\u90e8\u53d8\u91cf\u8868\u3001\u64cd\u4f5c\u6570\u6808\u3001\u52a8\u6001\u8fde\u63a5\u3001\u65b9\u6cd5\u51fa\u53e3\u7b49\u4fe1\u606f\u3002\u672c\u5730\u65b9\u6cd5\u6808\u4e0e\u865a\u62df\u673a\u6808\u7684\u533a\u522b\u662f\uff0c\u865a\u62df\u673a\u6808\u4e3a\u865a\u62df\u673a\u6267\u884cjava\u65b9\u6cd5\u670d\u52a1\uff0c\u800c\u672c\u5730\u65b9\u6cd5\u6808\u5219\u4e3a\u865a\u62df\u673a\u63d0\u4f9bnative\u65b9\u6cd5\u670d\u52a1\u3002<\/p>\n \u5728\u5355\u7ebf\u7a0b\u7684\u64cd\u4f5c\u4e2d\uff0c\u65e0\u8bba\u662f\u7531\u4e8e\u6808\u5e27\u592a\u5927\uff0c\u8fd8\u662f\u865a\u62df\u673a\u6808\u7a7a\u95f4\u592a\u5c0f\uff0c\u5f53\u6808\u7a7a\u95f4\u65e0\u6cd5\u5206\u914d\u65f6\uff0c\u865a\u62df\u673a\u629b\u51fa\u7684\u90fd\u662fStackOverflowError\u5f02\u5e38\uff0c\u800c\u4e0d\u4f1a\u5f97\u5230OutOfMemoryError\u5f02\u5e38\u3002\u800c\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\uff0c\u5219\u4f1a\u629b\u51faOutOfMemoryError\u5f02\u5e38\u3002<\/p>\n
java\u5806\u533a\u4e3b\u8981\u5b58\u653e\u5bf9\u8c61\u5b9e\u4f8b\u548c\u6570\u7ec4\u7b49\uff0c\u65b9\u6cd5\u533a\u4fdd\u5b58\u7c7b\u4fe1\u606f\u3001\u5e38\u91cf\u3001\u9759\u6001\u53d8\u91cf\u7b49\u7b49\u3002\u8fd0\u884c\u65f6\u5e38\u91cf\u6c60\u4e5f\u662f\u65b9\u6cd5\u533a\u7684\u4e00\u90e8\u5206\u3002\u8fd9\u4e24\u5757\u533a\u57df\u662f\u7ebf\u7a0b\u5171\u4eab\u7684\u533a\u57df\uff0c\u53ea\u4f1a\u629b\u51faOutOfMemoryError\u3002<\/p>\n \u4e0d\u77e5\u9053\u5404\u4f4d\u5728B\u7ad9\u770b\u89c1\u8fc7\u90a3\u4e2a\u9762\u8bd5\u7ecf\u5178\u573a\u666f\u6ca1\uff0c\u5728\u56de\u7b54java\u7684\u5185\u5b58\u8fd0\u884c\u6570\u636e\u533a\u7ed3\u6784\u65f6\uff0c\u4ee5\u4e0a\u7684\u529f\u80fd\u4f5c\u7528\u662f\u4e00\u65b9\u9762\uff0c\u5982\u679c\u56de\u7b54\u65f6\u628a\u5185\u5b58\u6ea2\u51fa\u95ee\u9898\u6dfb\u52a0\u4e0a\u662f\u4e00\u4e2a\u6781\u5927\u7684\u52a0\u5206\u9879\u3002<\/p>\n \u4e8c\u3001\u5185\u5b58\u6ea2\u51fa\u5b9e\u4f8b<\/strong><\/div>\n 1\u3001\u5806\u6ea2\u51fa<\/strong><\/span><\/div>\n \u65e2\u7136\u5806\u662f\u5b58\u653e\u5b9e\u4f8b\u5bf9\u8c61\u7684\uff0c\u90a3\u6211\u4eec\u5c31\u65e0\u7ebf\u521b\u5efa\u5b9e\u4f8b\u5bf9\u8c61\u3002\u8fd9\u6837\u5806\u533a\u8fdf\u65e9\u4f1a\u6ee1\u3002<\/p>\n \r\npublic class HeapOOM { \r\n static class User {} \r\n public static void main(String[] args) { \r\n List |