{
  "id": 355188,
  "title": "Is it worth using gc.collect() after del X where X is a very big object ?",
  "url": "/competitions/mayo-clinic-strip-ai/discussion/355188",
  "author_name": "Pierre Tisseur",
  "post_date": "2022-09-25T20:30:43.038000",
  "votes": 2,
  "comment_count": 2,
  "views": 0,
  "content": "<p>I try to fight with the \"Notebook Exceeded Allowed Compute\" error.  Trying to eliminate first the biggest image with os.path.getsize() but I would like to throw the minimum of image. I have seen that ram use is increasing even if the new image is smaller than the previous one. Maybe this is due to some delays to see the information. Is the python automatic garbage collector always manage ram better?</p>",
  "messages": [
    {
      "id": 1956079,
      "postDate": "2022-09-26T09:11:31.927Z",
      "content": "<p>I usually use <code>gc.collect()</code> alongside with <code>torch.cuda.empty_cache()</code></p>\n<pre><code>def clean_cache():\n    torch.cuda.empty_cache()\n    gc.collect()\n</code></pre>",
      "rawMarkdown": "I usually use `gc.collect()` alongside with `torch.cuda.empty_cache()`\n```\ndef clean_cache():\n    torch.cuda.empty_cache()\n    gc.collect()\n```",
      "votes": 1
    },
    {
      "id": 1955456,
      "postDate": "2022-09-26T02:45:08.323Z",
      "content": "<p>I usually use it along with the cell magic command %%time to optimize my code. This has helped me a lot and I think it is useful. </p>\n<p>I presume you need to use gc.collect with 3 sweeps as below- <br>\nfor g in range(3): collect(g)</p>",
      "rawMarkdown": "I usually use it along with the cell magic command %%time to optimize my code. This has helped me a lot and I think it is useful. \n\nI presume you need to use gc.collect with 3 sweeps as below- \nfor g in range(3): collect(g)",
      "votes": 2
    },
    {
      "id": 1955225,
      "postDate": "2022-09-25T20:30:43.037Z",
      "content": "<p>I try to fight with the \"Notebook Exceeded Allowed Compute\" error.  Trying to eliminate first the biggest image with os.path.getsize() but I would like to throw the minimum of image. I have seen that ram use is increasing even if the new image is smaller than the previous one. Maybe this is due to some delays to see the information. Is the python automatic garbage collector always manage ram better?</p>",
      "rawMarkdown": "I try to fight with the \"Notebook Exceeded Allowed Compute\" error.  Trying to eliminate first the biggest image with os.path.getsize() but I would like to throw the minimum of image. I have seen that ram use is increasing even if the new image is smaller than the previous one. Maybe this is due to some delays to see the information. Is the python automatic garbage collector always manage ram better?",
      "votes": 2
    }
  ],
  "comments": [
    {
      "id": 1956079,
      "author_name": "Thinh RE",
      "author_url": "",
      "post_date": "2022-09-26T09:11:31.927000",
      "content": "<p>I usually use <code>gc.collect()</code> alongside with <code>torch.cuda.empty_cache()</code></p>\n<pre><code>def clean_cache():\n    torch.cuda.empty_cache()\n    gc.collect()\n</code></pre>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1955456,
      "author_name": "Ravi Ramakrishnan",
      "author_url": "",
      "post_date": "2022-09-26T02:45:08.323000",
      "content": "<p>I usually use it along with the cell magic command %%time to optimize my code. This has helped me a lot and I think it is useful. </p>\n<p>I presume you need to use gc.collect with 3 sweeps as below- <br>\nfor g in range(3): collect(g)</p>",
      "votes": 2,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1956079": "I usually use `gc.collect()` alongside with `torch.cuda.empty_cache()`\n```\ndef clean_cache():\n    torch.cuda.empty_cache()\n    gc.collect()\n```",
    "1955456": "I usually use it along with the cell magic command %%time to optimize my code. This has helped me a lot and I think it is useful. \n\nI presume you need to use gc.collect with 3 sweeps as below- \nfor g in range(3): collect(g)",
    "1955225": "I try to fight with the \"Notebook Exceeded Allowed Compute\" error.  Trying to eliminate first the biggest image with os.path.getsize() but I would like to throw the minimum of image. I have seen that ram use is increasing even if the new image is smaller than the previous one. Maybe this is due to some delays to see the information. Is the python automatic garbage collector always manage ram better?"
  }
}