{"action":"created","issue":{"url":"https://api.github.com/repos/p0nce/d-idioms/issues/92","labels_url":"https://api.github.com/repos/p0nce/d-idioms/issues/92/labels{/name}","comments_url":"https://api.github.com/repos/p0nce/d-idioms/issues/92/comments","events_url":"https://api.github.com/repos/p0nce/d-idioms/issues/92/events","html_url":"https://github.com/p0nce/d-idioms/issues/92","id":129246577,"number":92,"title":"Potential problem in GC-proof resource class article","user":{"login":"jpf91","id":583238,"avatar_url":"https://avatars.githubusercontent.com/u/583238?v=3","gravatar_id":"","url":"https://api.github.com/users/jpf91","html_url":"https://github.com/jpf91","followers_url":"https://api.github.com/users/jpf91/followers","following_url":"https://api.github.com/users/jpf91/following{/other_user}","gists_url":"https://api.github.com/users/jpf91/gists{/gist_id}","starred_url":"https://api.github.com/users/jpf91/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpf91/subscriptions","organizations_url":"https://api.github.com/users/jpf91/orgs","repos_url":"https://api.github.com/users/jpf91/repos","events_url":"https://api.github.com/users/jpf91/events{/privacy}","received_events_url":"https://api.github.com/users/jpf91/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-27T19:38:44Z","updated_at":"2016-01-27T20:00:38Z","closed_at":null,"body":"The solution mentioned in the article is supposed to work with `object.destroy`. However, it doesn't explain that `object.destroy` reinitializes the class (overwrites contents with `.init`).\r\n\r\nSo the comment:\r\n```d\r\n        // Such a destructor must support repeated calls for\r\n        // the case when it is first called by destroy() and\r\n        // then called by the GC later\r\n        if (handle != null)\r\n        [...]\r\n        handle = null;\r\n```\r\n\r\nis correct, but I think it needs to be stressed that the destructor call by the GC will see the class `.init` value, not the value set in the destructor. So users actually have to check against the value used to initialize the field.\r\n\r\n\r\nAdditionally, I can't even get the GC to call the destructor after a `destroy` call. The [druntime code](https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L1352) is cryptic, but it seems that the code checks a hidden field in the class before calling the destructor. And this field seems to be set to null when the initializer is copied into the object:\r\nhttp://dpaste.dzfl.pl/4199205f4fee"},"comment":{"url":"https://api.github.com/repos/p0nce/d-idioms/issues/comments/175825567","html_url":"https://github.com/p0nce/d-idioms/issues/92#issuecomment-175825567","issue_url":"https://api.github.com/repos/p0nce/d-idioms/issues/92","id":175825567,"user":{"login":"p0nce","id":1067485,"avatar_url":"https://avatars.githubusercontent.com/u/1067485?v=3","gravatar_id":"","url":"https://api.github.com/users/p0nce","html_url":"https://github.com/p0nce","followers_url":"https://api.github.com/users/p0nce/followers","following_url":"https://api.github.com/users/p0nce/following{/other_user}","gists_url":"https://api.github.com/users/p0nce/gists{/gist_id}","starred_url":"https://api.github.com/users/p0nce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p0nce/subscriptions","organizations_url":"https://api.github.com/users/p0nce/orgs","repos_url":"https://api.github.com/users/p0nce/repos","events_url":"https://api.github.com/users/p0nce/events{/privacy}","received_events_url":"https://api.github.com/users/p0nce/received_events","type":"User","site_admin":false},"created_at":"2016-01-27T20:00:38Z","updated_at":"2016-01-27T20:00:38Z","body":"I always had a doubt about repeated calls actually. \r\nYou found that it is probably impossible. Makes much more sense that way, I also never got a destructor called multiple times when trying.\r\nThat will make the idiom less ugly to use in practice."}}