{"id":960690,"date":"2024-12-27T03:51:55","date_gmt":"2024-12-26T19:51:55","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/960690.html"},"modified":"2024-12-27T03:51:56","modified_gmt":"2024-12-26T19:51:56","slug":"python%e5%a6%82%e4%bd%95%e6%b8%85%e9%99%a4%e7%bc%93%e5%ad%98%e5%8c%ba","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/960690.html","title":{"rendered":"python\u5982\u4f55\u6e05\u9664\u7f13\u5b58\u533a"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25103122\/029f41af-8e68-4929-a04a-5e489e2ef525.webp\" alt=\"python\u5982\u4f55\u6e05\u9664\u7f13\u5b58\u533a\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u6e05\u9664\u7f13\u5b58\u533a\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528<code>gc.collect()<\/code>\u624b\u52a8\u5783\u573e\u56de\u6536\u3001\u4f7f\u7528<code>del<\/code>\u5220\u9664\u5bf9\u8c61\u3001\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u5237\u65b0\u8f93\u51fa\u7f13\u51b2\u533a\u3002<\/strong>\u5176\u4e2d\uff0c<code>gc.collect()<\/code> \u662f\u4e00\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u5b83\u5f3a\u5236\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u6e05\u7406\u4e0d\u518d\u4f7f\u7528\u7684\u5185\u5b58\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u4f7f\u7528 <code>gc.collect()<\/code> \u6765\u6e05\u9664\u7f13\u5b58\u533a\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p><code>gc.collect()<\/code> \u662f Python \u7684\u5783\u573e\u56de\u6536\u6a21\u5757 <code>gc<\/code> \u4e2d\u7684\u4e00\u4e2a\u65b9\u6cd5\uff0c\u7528\u4e8e\u624b\u52a8\u89e6\u53d1\u5783\u573e\u56de\u6536\u3002Python \u7684\u5185\u5b58\u7ba1\u7406\u5668\u4f1a\u81ea\u52a8\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u4f46\u6709\u65f6\u5019\u5728\u7279\u5b9a\u573a\u666f\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u624b\u52a8\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\u6765\u7acb\u5373\u91ca\u653e\u5185\u5b58\u3002\u4f8b\u5982\uff0c\u5f53\u5904\u7406\u5927\u91cf\u6570\u636e\u7684\u7a0b\u5e8f\u9700\u8981\u5728\u67d0\u4e2a\u7279\u5b9a\u65f6\u95f4\u70b9\u91ca\u653e\u5185\u5b58\u4ee5\u4fdd\u8bc1\u6027\u80fd\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u8c03\u7528 <code>gc.collect()<\/code> \u6765\u786e\u4fdd\u672a\u5f15\u7528\u7684\u5bf9\u8c61\u88ab\u53ca\u65f6\u6e05\u7406\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>PYTHON\u7f13\u5b58\u533a\u6e05\u9664\u65b9\u6cd5\u8be6\u89e3<\/strong><\/h2>\n<p><p>\u5728\u7f16\u7a0b\u8fc7\u7a0b\u4e2d\uff0c\u7f13\u5b58\u533a\u7684\u7ba1\u7406\u5bf9\u7a0b\u5e8f\u6027\u80fd\u548c\u8d44\u6e90\u4f7f\u7528\u6709\u7740\u91cd\u8981\u7684\u5f71\u54cd\u3002\u5728Python\u4e2d\uff0c\u4e86\u89e3\u5982\u4f55\u6e05\u9664\u7f13\u5b58\u533a\u662f\u63d0\u9ad8\u7a0b\u5e8f\u6548\u7387\u7684\u5173\u952e\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u591a\u79cd\u65b9\u6cd5\uff0c\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u597d\u5730\u7ba1\u7406Python\u7f13\u5b58\u533a\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u624b\u52a8\u5783\u573e\u56de\u6536<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5783\u573e\u56de\u6536\u662f\u81ea\u52a8\u8fdb\u884c\u7684\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u624b\u52a8\u5783\u573e\u56de\u6536\u53ef\u4ee5\u5e2e\u52a9\u91ca\u653e\u5185\u5b58\u3002<\/p>\n<\/p>\n<p><h3>1.1 \u4f7f\u7528gc.collect()<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86<code>gc<\/code>\u6a21\u5757\u7528\u4e8e\u5783\u573e\u56de\u6536\u7ba1\u7406\u3002\u901a\u8fc7\u8c03\u7528<code>gc.collect()<\/code>\uff0c\u53ef\u4ee5\u5f3a\u5236\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u6e05\u9664\u672a\u5f15\u7528\u7684\u5bf9\u8c61\u3002\u8fd9\u5728\u5185\u5b58\u5bc6\u96c6\u578b\u5e94\u7528\u4e2d\u5c24\u4e3a\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import gc<\/p>\n<h2><strong>\u5f3a\u5236\u8fdb\u884c\u5783\u573e\u56de\u6536<\/strong><\/h2>\n<p>gc.collect()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528<code>gc.collect()<\/code>\u7684\u4e00\u4e2a\u5e38\u89c1\u573a\u666f\u662f\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u540e\uff0c\u5e0c\u671b\u53ca\u65f6\u91ca\u653e\u5185\u5b58\uff0c\u4ee5\u4fbf\u5728\u540e\u7eed\u64cd\u4f5c\u4e2d\u6709\u66f4\u591a\u7684\u5185\u5b58\u53ef\u7528\u3002<\/p>\n<\/p>\n<p><h3>1.2 <code>gc<\/code>\u6a21\u5757\u7684\u5176\u4ed6\u529f\u80fd<\/h3>\n<\/p>\n<p><p>\u9664\u4e86<code>gc.collect()<\/code>\uff0c<code>gc<\/code>\u6a21\u5757\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u5176\u4ed6\u529f\u80fd\uff0c\u4f8b\u5982\u8ddf\u8e2a\u5bf9\u8c61\u5206\u914d\u548c\u89e3\u9664\u5206\u914d\u3001\u8bbe\u7f6e\u5783\u573e\u56de\u6536\u7684\u9608\u503c\u7b49\u3002\u8fd9\u4e9b\u529f\u80fd\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u7cbe\u7ec6\u5730\u63a7\u5236\u5783\u573e\u56de\u6536\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import gc<\/p>\n<h2><strong>\u83b7\u53d6\u5783\u573e\u56de\u6536\u7684\u9608\u503c<\/strong><\/h2>\n<p>threshold = gc.get_threshold()<\/p>\n<p>print(&quot;\u5f53\u524d\u5783\u573e\u56de\u6536\u9608\u503c:&quot;, threshold)<\/p>\n<h2><strong>\u8bbe\u7f6e\u65b0\u7684\u5783\u573e\u56de\u6536\u9608\u503c<\/strong><\/h2>\n<p>gc.set_threshold(700, 10, 10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8c03\u6574\u5783\u573e\u56de\u6536\u7684\u9608\u503c\u53ef\u4ee5\u5e2e\u52a9\u4f18\u5316\u5185\u5b58\u7ba1\u7406\uff0c\u5c24\u5176\u662f\u5728\u7279\u5b9a\u5e94\u7528\u573a\u666f\u4e0b\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u5220\u9664\u5bf9\u8c61<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u901a\u8fc7<code>del<\/code>\u5173\u952e\u5b57\u5220\u9664\u4e0d\u518d\u9700\u8981\u7684\u5bf9\u8c61\uff0c\u53ef\u4ee5\u5e2e\u52a9\u91ca\u653e\u5185\u5b58\u3002<\/p>\n<\/p>\n<p><h3>2.1 \u4f7f\u7528del\u5173\u952e\u5b57<\/h3>\n<\/p>\n<p><p><code>del<\/code>\u5173\u952e\u5b57\u7528\u4e8e\u5220\u9664\u4e00\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\u3002\u5f53\u4e00\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570\u964d\u4e3a0\u65f6\uff0cPython\u4f1a\u81ea\u52a8\u56de\u6536\u8be5\u5bf9\u8c61\u7684\u5185\u5b58\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5927\u5bf9\u8c61<\/p>\n<p>large_object = [i for i in range(1000000)]<\/p>\n<h2><strong>\u5220\u9664\u5bf9\u8c61\u4ee5\u91ca\u653e\u5185\u5b58<\/strong><\/h2>\n<p>del large_object<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u76f4\u63a5\uff0c\u9002\u7528\u4e8e\u4e0d\u518d\u9700\u8981\u7684\u53d8\u91cf\u6216\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h3>2.2 del\u7684\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u6216\u5927\u578b\u6570\u636e\u7ed3\u6784\u65f6\uff0c\u4f7f\u7528<code>del<\/code>\u5220\u9664\u4e0d\u518d\u9700\u8981\u7684\u4e2d\u95f4\u53d8\u91cf\uff0c\u53ef\u4ee5\u6709\u6548\u51cf\u5c11\u5185\u5b58\u5360\u7528\u3002\u4f8b\u5982\uff0c\u5728\u6570\u636e\u5904\u7406\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e34\u65f6\u53d8\u91cf\u5728\u7528\u5b8c\u540e\u7acb\u5373\u5220\u9664\uff0c\u53ef\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u5185\u5b58\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u5237\u65b0\u8f93\u51fa\u7f13\u51b2\u533a<\/h2>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u8f93\u51fa\u7acb\u5373\u663e\u793a\u5230\u5c4f\u5e55\u4e0a\u6216\u5199\u5165\u6587\u4ef6\u4e2d\uff0c\u8fd9\u65f6\u9700\u8981\u5237\u65b0\u8f93\u51fa\u7f13\u51b2\u533a\u3002<\/p>\n<\/p>\n<p><h3>3.1 \u4f7f\u7528os\u6a21\u5757\u5237\u65b0\u7f13\u51b2\u533a<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u8f93\u51fa\u901a\u5e38\u662f\u7f13\u51b2\u7684\u3002\u901a\u8fc7<code>os<\/code>\u6a21\u5757\uff0c\u53ef\u4ee5\u624b\u52a8\u5237\u65b0\u8f93\u51fa\u7f13\u51b2\u533a\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>import os<\/p>\n<h2><strong>\u5237\u65b0\u6807\u51c6\u8f93\u51fa\u7f13\u51b2\u533a<\/strong><\/h2>\n<p>sys.stdout.flush()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u5e38\u7528\u4e8e\u9700\u8981\u7acb\u5373\u663e\u793a\u8f93\u51fa\u7ed3\u679c\u7684\u573a\u666f\uff0c\u4f8b\u5982\u5b9e\u65f6\u65e5\u5fd7\u8bb0\u5f55\u6216\u4ea4\u4e92\u5f0f\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>3.2 \u4f7f\u7528flush\u53c2\u6570<\/h3>\n<\/p>\n<p><p>Python\u7684<code>print()<\/code>\u51fd\u6570\u63d0\u4f9b\u4e86\u4e00\u4e2a<code>flush<\/code>\u53c2\u6570\uff0c\u53ef\u4ee5\u5728\u6bcf\u6b21\u8f93\u51fa\u540e\u7acb\u5373\u5237\u65b0\u7f13\u51b2\u533a\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;\u7acb\u5373\u8f93\u51fa&quot;, flush=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u9ad8\u6548\uff0c\u9002\u7528\u4e8e\u9700\u8981\u5b9e\u65f6\u8f93\u51fa\u7684\u573a\u5408\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u7684\u5176\u4ed6\u7b56\u7565<\/h2>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u8fd8\u6709\u5176\u4ed6\u7b56\u7565\uff0c\u4f8b\u5982\u4f7f\u7528\u751f\u6210\u5668\u3001\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u7b49\u3002<\/p>\n<\/p>\n<p><h3>4.1 \u4f7f\u7528\u751f\u6210\u5668<\/h3>\n<\/p>\n<p><p>\u751f\u6210\u5668\u662f\u4e00\u79cd\u60f0\u6027\u6c42\u503c\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u5728\u9700\u8981\u65f6\u624d\u751f\u6210\u6570\u636e\uff0c\u4ece\u800c\u8282\u7701\u5185\u5b58\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def large_range(n):<\/p>\n<p>    for i in range(n):<\/p>\n<p>        yield i<\/p>\n<h2><strong>\u4f7f\u7528\u751f\u6210\u5668\u4ee3\u66ff\u5217\u8868<\/strong><\/h2>\n<p>for i in large_range(1000000):<\/p>\n<p>    pass<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u751f\u6210\u5668\u907f\u514d\u4e86\u5c06\u6240\u6709\u6570\u636e\u540c\u65f6\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u9002\u7528\u4e8e\u5904\u7406\u5927\u6570\u636e\u96c6\u7684\u573a\u5408\u3002<\/p>\n<\/p>\n<p><h3>4.2 \u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784<\/h3>\n<\/p>\n<p><p>\u6839\u636e\u6570\u636e\u7684\u7279\u70b9\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u6709\u6548\u51cf\u5c11\u5185\u5b58\u5360\u7528\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u96c6\u5408\u800c\u4e0d\u662f\u5217\u8868\u5b58\u50a8\u552f\u4e00\u5143\u7d20\uff0c\u4f7f\u7528\u6570\u7ec4\u4ee3\u66ff\u5217\u8868\u5b58\u50a8\u6570\u503c\u6570\u636e\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import array<\/p>\n<h2><strong>\u4f7f\u7528\u6570\u7ec4\u4ee3\u66ff\u5217\u8868<\/strong><\/h2>\n<p>numbers = array.array(&#39;i&#39;, [1, 2, 3, 4, 5])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0d\u540c\u7684\u6570\u636e\u7ed3\u6784\u5728\u5185\u5b58\u4f7f\u7528\u548c\u64cd\u4f5c\u6027\u80fd\u4e0a\u6709\u4e0d\u540c\u7684\u8868\u73b0\uff0c\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6574\u4f53\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u603b\u7ed3\u4e0e\u5efa\u8bae<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u6e05\u9664\u7f13\u5b58\u533a\u548c\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u662f\u63d0\u9ad8\u7a0b\u5e8f\u6027\u80fd\u7684\u91cd\u8981\u624b\u6bb5\u3002\u901a\u8fc7\u624b\u52a8\u5783\u573e\u56de\u6536\u3001\u5220\u9664\u5bf9\u8c61\u3001\u5237\u65b0\u8f93\u51fa\u7f13\u51b2\u533a\u4ee5\u53ca\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u7b56\u7565\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u5185\u5b58\uff0c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6548\u7387\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5408\u7406\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6839\u636e\u5177\u4f53\u9700\u6c42\u8fdb\u884c\u5185\u5b58\u7ba1\u7406\u4f18\u5316\uff0c\u662f\u7f16\u5199\u9ad8\u6548Python\u4ee3\u7801\u7684\u5173\u952e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u67e5\u770b\u5f53\u524d\u7684\u7f13\u5b58\u533a\u5185\u5bb9\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u7f13\u5b58\u533a\u7684\u5185\u5bb9\u901a\u5e38\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u4e0a\u4e0b\u6587\uff0c\u6bd4\u5982\u6587\u4ef6\u64cd\u4f5c\u6216\u7f51\u7edc\u8bf7\u6c42\u7b49\u3002\u8981\u67e5\u770b\u7f13\u5b58\u5185\u5bb9\uff0c\u53ef\u4ee5\u4f7f\u7528\u76f8\u5e94\u7684\u6a21\u5757\u548c\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u6587\u4ef6\u5bf9\u8c61\uff0c\u53ef\u4ee5\u4f7f\u7528<code>read()<\/code>\u65b9\u6cd5\u8bfb\u53d6\u5f53\u524d\u7f13\u5b58\u533a\u7684\u5185\u5bb9\uff0c\u800c\u5bf9\u4e8e\u7f51\u7edc\u8bf7\u6c42\uff0c\u53ef\u4ee5\u4f7f\u7528<code>response.content<\/code>\u6216<code>response.text<\/code>\u6765\u67e5\u770b\u8bf7\u6c42\u7684\u54cd\u5e94\u5185\u5bb9\u3002<\/p>\n<p><strong>\u6e05\u9664\u7f13\u5b58\u533a\u662f\u5426\u4f1a\u5f71\u54cd\u7a0b\u5e8f\u7684\u6027\u80fd\uff1f<\/strong><br \/>\u6e05\u9664\u7f13\u5b58\u533a\u53ef\u80fd\u4f1a\u5bf9\u7a0b\u5e8f\u7684\u6027\u80fd\u4ea7\u751f\u5f71\u54cd\uff0c\u5c24\u5176\u662f\u5728\u9891\u7e41\u8bfb\u5199\u64cd\u4f5c\u65f6\u3002\u9891\u7e41\u6e05\u9664\u7f13\u5b58\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u7684\u8fd0\u884c\u901f\u5ea6\u53d8\u6162\uff0c\u56e0\u4e3a\u6bcf\u6b21\u6e05\u9664\u90fd\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u9700\u8981\u91cd\u65b0\u52a0\u8f7d\u6570\u636e\u3002\u4e3a\u4e86\u4f18\u5316\u6027\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u5728\u5408\u9002\u7684\u65f6\u673a\u8fdb\u884c\u7f13\u5b58\u6e05\u7406\uff0c\u800c\u4e0d\u662f\u5728\u6bcf\u6b21\u8bfb\u5199\u64cd\u4f5c\u540e\u90fd\u6e05\u9664\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\uff0c\u7f13\u5b58\u533a\u6e05\u7406\u7684\u6700\u4f73\u5b9e\u8df5\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u7f13\u5b58\u533a\u6e05\u7406\u7684\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\u4f7f\u7528\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u6765\u786e\u4fdd\u8d44\u6e90\u7684\u6b63\u786e\u91ca\u653e\uff0c\u5b9a\u671f\u68c0\u67e5\u548c\u6e05\u7406\u4e0d\u518d\u4f7f\u7528\u7684\u7f13\u5b58\u6570\u636e\uff0c\u4ee5\u53ca\u4f7f\u7528\u5408\u9002\u7684\u7f13\u5b58\u7b56\u7565\uff08\u5982LRU\u7f13\u5b58\uff09\u6765\u7ba1\u7406\u5185\u5b58\u4f7f\u7528\u3002\u4f7f\u7528<code>with<\/code>\u8bed\u53e5\u53ef\u4ee5\u5e2e\u52a9\u81ea\u52a8\u5904\u7406\u6587\u4ef6\u548c\u7f51\u7edc\u8fde\u63a5\u7684\u5173\u95ed\uff0c\u4ece\u800c\u6709\u6548\u7ba1\u7406\u7f13\u5b58\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u6e05\u9664\u7f13\u5b58\u533a\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528gc.collect()\u624b\u52a8\u5783\u573e\u56de\u6536\u3001\u4f7f\u7528del\u5220\u9664\u5bf9\u8c61\u3001\u4f7f\u7528os\u6a21 [&hellip;]","protected":false},"author":3,"featured_media":960696,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/960690"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=960690"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/960690\/revisions"}],"predecessor-version":[{"id":960698,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/960690\/revisions\/960698"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/960696"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=960690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=960690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=960690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}