{"action":"closed","issue":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/1632","labels_url":"https://api.github.com/repos/nim-lang/Nim/issues/1632/labels{/name}","comments_url":"https://api.github.com/repos/nim-lang/Nim/issues/1632/comments","events_url":"https://api.github.com/repos/nim-lang/Nim/issues/1632/events","html_url":"https://github.com/nim-lang/Nim/issues/1632","id":47882141,"number":1632,"title":"Destructors don't work when object instantiated inside template","user":{"login":"jovial","id":1368360,"avatar_url":"https://avatars.githubusercontent.com/u/1368360?v=3","gravatar_id":"","url":"https://api.github.com/users/jovial","html_url":"https://github.com/jovial","followers_url":"https://api.github.com/users/jovial/followers","following_url":"https://api.github.com/users/jovial/following{/other_user}","gists_url":"https://api.github.com/users/jovial/gists{/gist_id}","starred_url":"https://api.github.com/users/jovial/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jovial/subscriptions","organizations_url":"https://api.github.com/users/jovial/orgs","repos_url":"https://api.github.com/users/jovial/repos","events_url":"https://api.github.com/users/jovial/events{/privacy}","received_events_url":"https://api.github.com/users/jovial/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nim-lang/Nim/labels/Destructor","name":"Destructor","color":"d4c5f9"},{"url":"https://api.github.com/repos/nim-lang/Nim/labels/Low%20Priority","name":"Low Priority","color":"4ed600"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2014-11-05T20:12:27Z","updated_at":"2015-08-05T19:49:00Z","closed_at":"2015-08-05T19:49:00Z","body":"Shouldn't the destructor be called at the end of the main function?\r\n\r\n```nimrod\r\ntype\r\n  Foo = object of RootObj\r\n    x: int\r\n\r\nproc destroy(a: var Foo) {.override.} =\r\n  echo \"destroy Foo: \" & repr a\r\n\r\ntemplate toFooPtr(a: int{lit}): ptr Foo =\r\n  var temp = Foo(x:a)\r\n  temp.addr\r\n\r\nproc test(a: ptr Foo) =\r\n  echo a[].x\r\n\r\nproc main =\r\n   test(toFooPtr(5))\r\n   test(toFooPtr(123))\r\n  \r\nmain()\r\n```\r\n\r\nWorks when you get rid of destructor."}}