{"id":10952,"date":"2023-11-28T21:48:17","date_gmt":"2023-11-28T13:48:17","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=10952"},"modified":"2023-12-07T16:04:34","modified_gmt":"2023-12-07T08:04:34","slug":"jvm-zhong-stackoverflowerror-he-outofmemeryerror-d","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/jvm-zhong-stackoverflowerror-he-outofmemeryerror-d\/","title":{"rendered":"JVM \u4e2d StackOverflowError \u548c OutOfMemeryError \u7684\u533a\u522b\uff1f"},"content":{"rendered":"<p><code>StackOverflowError<\/code> \u548c <code>OutOfMemoryError<\/code> \u90fd\u662fJava\u865a\u62df\u673a\u5728\u8fd0\u884c\u65f6\u629b\u51fa\u7684\u9519\u8bef\uff08Error\uff09\u7684\u5b50\u7c7b\uff0c\u8868\u793a\u7a0b\u5e8f\u5728\u6267\u884c\u65f6\u9047\u5230\u4e86\u4e00\u4e9b\u65e0\u6cd5\u6062\u590d\u7684\u9519\u8bef\u60c5\u51b5\u3002\u5b83\u4eec\u5206\u522b\u4ee3\u8868\u4e86\u4e24\u79cd\u4e0d\u540c\u7684\u9519\u8bef\u7c7b\u578b\uff1a<\/p>\n<ol>\n<li>\n<strong>StackOverflowError:<\/strong><\/p>\n<ul>\n<li><strong>\u539f\u56e0\uff1a<\/strong> \u5f53\u4e00\u4e2a\u7ebf\u7a0b\u7684\u8c03\u7528\u6808\uff08\u65b9\u6cd5\u8c03\u7528\u7684\u5d4c\u5957\uff09\u8fc7\u6df1\uff0c\u5bfc\u81f4\u6808\u5e27\u65e0\u6cd5\u518d\u88ab\u538b\u5165\u8c03\u7528\u6808\u65f6\uff0c\u5c31\u4f1a\u629b\u51fa <code>StackOverflowError<\/code>\u3002<\/li>\n<li><strong>\u5178\u578b\u573a\u666f\uff1a<\/strong> \u9012\u5f52\u8c03\u7528\u672a\u6b63\u786e\u7ec8\u6b62\uff0c\u5bfc\u81f4\u8c03\u7528\u6808\u65e0\u9650\u589e\u957f\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-java\">public class StackOverflowExample {\n    public static void recursiveMethod() {\n        recursiveMethod();\n    }\n\n    public static void main(String[] args) {\n        recursiveMethod();\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c<code>recursiveMethod<\/code> \u65b9\u6cd5\u65e0\u9650\u9012\u5f52\u8c03\u7528\uff0c\u5bfc\u81f4\u8c03\u7528\u6808\u6ea2\u51fa\uff0c\u6700\u7ec8\u629b\u51fa <code>StackOverflowError<\/code>\u3002\n<\/li>\n<li>\n<strong>OutOfMemoryError:<\/strong><\/p>\n<ul>\n<li><strong>\u539f\u56e0\uff1a<\/strong> \u5f53Java\u865a\u62df\u673a\u65e0\u6cd5\u5206\u914d\u6240\u9700\u7684\u5185\u5b58\u7a7a\u95f4\u65f6\uff0c\u5c31\u4f1a\u629b\u51fa <code>OutOfMemoryError<\/code>\u3002<\/li>\n<li><strong>\u5178\u578b\u573a\u666f\uff1a<\/strong> \u5806\u5185\u5b58\u6ea2\u51fa\u3001\u6c38\u4e45\u4ee3\/\u5143\u7a7a\u95f4\u6ea2\u51fa\u3001\u6808\u5185\u5b58\u6ea2\u51fa\u7b49\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-java\">public class OutOfMemoryExample {\n    public static void main(String[] args) {\n        List&lt;Object&gt; list = new ArrayList&lt;&gt;();\n        while (true) {\n            list.add(new Object());\n        }\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u901a\u8fc7\u65e0\u9650\u5411\u5217\u8868\u4e2d\u6dfb\u52a0\u5bf9\u8c61\uff0c\u6700\u7ec8\u5bfc\u81f4\u5806\u5185\u5b58\u6ea2\u51fa\uff0c\u629b\u51fa <code>OutOfMemoryError<\/code>\u3002\n<\/li>\n<\/ol>\n<p>\u603b\u7684\u6765\u8bf4\uff0c<code>StackOverflowError<\/code> \u4e3b\u8981\u4e0e\u8c03\u7528\u6808\u7684\u6df1\u5ea6\u6709\u5173\uff0c\u800c <code>OutOfMemoryError<\/code> \u5219\u4e0e\u5185\u5b58\u5206\u914d\u6709\u5173\uff0c\u53ef\u80fd\u53d1\u751f\u5728\u5806\u3001\u6c38\u4e45\u4ee3\/\u5143\u7a7a\u95f4\u6216\u6808\u7b49\u4e0d\u540c\u7684\u5185\u5b58\u533a\u57df\u3002\u5904\u7406\u8fd9\u4e24\u79cd\u9519\u8bef\u9700\u8981\u5206\u522b\u5173\u6ce8\u8c03\u7528\u6808\u6df1\u5ea6\u548c\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>StackOverflowError \u548c OutOfMemoryError \u90fd\u662fJava\u865a\u62df\u673a\u5728\u8fd0\u884c\u65f6\u629b\u51fa\u7684\u9519 [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[119],"tags":[],"class_list":["post-10952","post","type-post","status-publish","format-standard","hentry","category-jvm"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/10952","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=10952"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/10952\/revisions"}],"predecessor-version":[{"id":16921,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/10952\/revisions\/16921"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=10952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=10952"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=10952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}