{
  "id": "python/matplotlib-memory-leak-animation",
  "signature": "RuntimeWarning: More than 20 figures have been opened. Figures created with the pyplot interface (matplotlib.pyplot) are retained until explicitly closed and may consume too much memory.",
  "signature_zh": "RuntimeWarning: 已打开超过20个图形。通过pyplot接口(matplotlib.pyplot)创建的图形会保留直到显式关闭，可能消耗过多内存。",
  "regex": "RuntimeWarning:\\ More\\ than\\ 20\\ figures\\ have\\ been\\ opened\\.\\ Figures\\ created\\ with\\ the\\ pyplot\\ interface\\ \\(matplotlib\\.pyplot\\)\\ are\\ retained\\ until\\ explicitly\\ closed\\ and\\ may\\ consume\\ too\\ much\\ memory\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Creating many figures in a loop without closing them, leading to memory accumulation.",
  "root_cause_type": "generic",
  "root_cause_zh": "在循环中创建了大量图形但未关闭，导致内存累积。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Increasing the warning threshold via rcParams",
      "why_fails": "This silences the warning but does not fix the memory leak.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using plt.ioff() to disable interactive mode",
      "why_fails": "This only affects display, not memory management.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Close figures after use with plt.close()",
      "success_rate": 0.95,
      "how": "for i in range(100): plt.figure(); plt.plot([1,2,3]); plt.close()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use plt.close('all') at the end of the loop",
      "success_rate": 0.9,
      "how": "for i in range(100): plt.figure(); plt.plot([1,2,3]); plt.close('all')",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}