{"action":"created","issue":{"url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/28","labels_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/28/comments","events_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/28/events","html_url":"https://github.com/libgit2/libgit2sharp/issues/28","id":927966,"number":28,"title":"Correct usage of the using statement should be documented","user":{"login":"yysun","id":170547,"avatar_url":"https://avatars.githubusercontent.com/u/170547?v=3","gravatar_id":"","url":"https://api.github.com/users/yysun","html_url":"https://github.com/yysun","followers_url":"https://api.github.com/users/yysun/followers","following_url":"https://api.github.com/users/yysun/following{/other_user}","gists_url":"https://api.github.com/users/yysun/gists{/gist_id}","starred_url":"https://api.github.com/users/yysun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yysun/subscriptions","organizations_url":"https://api.github.com/users/yysun/orgs","repos_url":"https://api.github.com/users/yysun/repos","events_url":"https://api.github.com/users/yysun/events{/privacy}","received_events_url":"https://api.github.com/users/yysun/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/libgit2/libgit2sharp/labels/Doc","name":"Doc","color":"02e10c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2011-05-19T16:51:50Z","updated_at":"2015-07-18T03:06:58Z","closed_at":null,"body":"Hi,\n\nI have an example listed below. Can you see any problem from it?\n\n        public IEnumerable<string> GetRefs()\n        {\n            var tempFolder = \".....\";\n\n            using (var repository = new LibGit2Sharp.Repository(tempFolder))\n            {\n                return from r in repository.Refs\n                           select r.CanonicalName;\n            }\n        }\n\n        [TestMethod()]\n        public void GetRefsTest()\n        {\n            var refs = GetRefs();\n            foreach (var r in refs)\n            {\n                Console.WriteLine(r);\n            }\n        }\n\n\nThe test method GetRefsTest will throw exception: System.ObjectDisposedException: Safe handle has been closed.\n\n\nRegards,\n\nyysun"},"comment":{"url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/comments/122477247","html_url":"https://github.com/libgit2/libgit2sharp/issues/28#issuecomment-122477247","issue_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/28","id":122477247,"user":{"login":"john-grandy-opentable","id":3277564,"avatar_url":"https://avatars.githubusercontent.com/u/3277564?v=3","gravatar_id":"","url":"https://api.github.com/users/john-grandy-opentable","html_url":"https://github.com/john-grandy-opentable","followers_url":"https://api.github.com/users/john-grandy-opentable/followers","following_url":"https://api.github.com/users/john-grandy-opentable/following{/other_user}","gists_url":"https://api.github.com/users/john-grandy-opentable/gists{/gist_id}","starred_url":"https://api.github.com/users/john-grandy-opentable/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/john-grandy-opentable/subscriptions","organizations_url":"https://api.github.com/users/john-grandy-opentable/orgs","repos_url":"https://api.github.com/users/john-grandy-opentable/repos","events_url":"https://api.github.com/users/john-grandy-opentable/events{/privacy}","received_events_url":"https://api.github.com/users/john-grandy-opentable/received_events","type":"User","site_admin":false},"created_at":"2015-07-18T03:06:58Z","updated_at":"2015-07-18T03:06:58Z","body":"#Therzok would you say best practice for `using(Repository)` is once per method ?  or would you say a elevated scope ( e.g. class-level ) is a better practice ?\r\n\r\nBecause I was receiving `Access Denied` errors on `.git\\index`and `.git\\index.lock` I became concerned I wasn't releasing resources.  So I moved away from a single global `Repository` instance and attempted to isolate usage of `Repository` to the narrowest ranges possible - which in many cases meant multiple `using()` statements per method.  But now I'm getting run-time exceptions `safe handle has been closed` which indicates resources are not available even though I've re-instantiated the `Repository` object."}}