{"action":"created","issue":{"url":"https://api.github.com/repos/django/django/issues/6259","repository_url":"https://api.github.com/repos/django/django","labels_url":"https://api.github.com/repos/django/django/issues/6259/labels{/name}","comments_url":"https://api.github.com/repos/django/django/issues/6259/comments","events_url":"https://api.github.com/repos/django/django/issues/6259/events","html_url":"https://github.com/django/django/pull/6259","id":139466729,"number":6259,"title":"Fixed #26306 -- Memory leak in cached template loader","user":{"login":"AlexHill","id":1011483,"avatar_url":"https://avatars.githubusercontent.com/u/1011483?v=3","gravatar_id":"","url":"https://api.github.com/users/AlexHill","html_url":"https://github.com/AlexHill","followers_url":"https://api.github.com/users/AlexHill/followers","following_url":"https://api.github.com/users/AlexHill/following{/other_user}","gists_url":"https://api.github.com/users/AlexHill/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexHill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexHill/subscriptions","organizations_url":"https://api.github.com/users/AlexHill/orgs","repos_url":"https://api.github.com/users/AlexHill/repos","events_url":"https://api.github.com/users/AlexHill/events{/privacy}","received_events_url":"https://api.github.com/users/AlexHill/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-03-09T03:38:52Z","updated_at":"2016-04-11T14:24:24Z","closed_at":"2016-03-16T16:45:43Z","pull_request":{"url":"https://api.github.com/repos/django/django/pulls/6259","html_url":"https://github.com/django/django/pull/6259","diff_url":"https://github.com/django/django/pull/6259.diff","patch_url":"https://github.com/django/django/pull/6259.patch"},"body":"This fixes two related issues in the caching template loader, a memory leak bug and a memory use regression.\r\n\r\nIn 1.8, the thing that is cached when a template isn't found is the TemplateDoesNotExist class itself. When the debug view wants to know which paths were searched while looking for the template, it consults the rendering engine again. In 1.9, that debug information is stored on an exception instance, and those exceptions are cached.\r\n\r\nThe memory leak comes from the repeated re-raising of the same cached exception, which results in references to the `TemplateResponse` for each failed request persisting deep in the exception's context/stack information. The fix is to raise a new exception each cache hit, instead of repeatedly raising the cached exception.\r\n\r\nThe memory use regression comes from the intentional caching of every checked template path for each failed template, for debug purposes. In some projects that can end up eating all your memory. This is fixed by reverting to the 1.8 behaviour – simply caching the `TemplateDoesNotExist` class – when template debugging is not enabled.\r\n"},"comment":{"url":"https://api.github.com/repos/django/django/issues/comments/208371825","html_url":"https://github.com/django/django/pull/6259#issuecomment-208371825","issue_url":"https://api.github.com/repos/django/django/issues/6259","id":208371825,"user":{"login":"timgraham","id":411869,"avatar_url":"https://avatars.githubusercontent.com/u/411869?v=3","gravatar_id":"","url":"https://api.github.com/users/timgraham","html_url":"https://github.com/timgraham","followers_url":"https://api.github.com/users/timgraham/followers","following_url":"https://api.github.com/users/timgraham/following{/other_user}","gists_url":"https://api.github.com/users/timgraham/gists{/gist_id}","starred_url":"https://api.github.com/users/timgraham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timgraham/subscriptions","organizations_url":"https://api.github.com/users/timgraham/orgs","repos_url":"https://api.github.com/users/timgraham/repos","events_url":"https://api.github.com/users/timgraham/events{/privacy}","received_events_url":"https://api.github.com/users/timgraham/received_events","type":"User","site_admin":false},"created_at":"2016-04-11T14:24:24Z","updated_at":"2016-04-11T14:24:24Z","body":"You might be encountering a different issue. As far as I understand, the issues addressed here are new in 1.9."}}