{"action":"opened","issue":{"url":"https://api.github.com/repos/paulcbetts/ModernHttpClient/issues/162","labels_url":"https://api.github.com/repos/paulcbetts/ModernHttpClient/issues/162/labels{/name}","comments_url":"https://api.github.com/repos/paulcbetts/ModernHttpClient/issues/162/comments","events_url":"https://api.github.com/repos/paulcbetts/ModernHttpClient/issues/162/events","html_url":"https://github.com/paulcbetts/ModernHttpClient/issues/162","id":85635187,"number":162,"title":"iOS NativeMessageHandler has Memory Leak","user":{"login":"hieuctrac","id":5995526,"avatar_url":"https://avatars.githubusercontent.com/u/5995526?v=3","gravatar_id":"","url":"https://api.github.com/users/hieuctrac","html_url":"https://github.com/hieuctrac","followers_url":"https://api.github.com/users/hieuctrac/followers","following_url":"https://api.github.com/users/hieuctrac/following{/other_user}","gists_url":"https://api.github.com/users/hieuctrac/gists{/gist_id}","starred_url":"https://api.github.com/users/hieuctrac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hieuctrac/subscriptions","organizations_url":"https://api.github.com/users/hieuctrac/orgs","repos_url":"https://api.github.com/users/hieuctrac/repos","events_url":"https://api.github.com/users/hieuctrac/events{/privacy}","received_events_url":"https://api.github.com/users/hieuctrac/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-05T21:18:47Z","updated_at":"2015-06-05T21:18:47Z","closed_at":null,"body":"I created a sample project to demo this. The code for the view controller is below. I will email you the sample code and the instruments log to (paul@paulbetts.org). This may also be apparent in the NativeCookieHandler.\r\n\r\n---\r\n\r\nusing System;\r\nusing System.Drawing;\r\nusing System.Net;\r\nusing System.Net.Http;\r\nusing System.Threading;\r\nusing System.Threading.Tasks;\r\n\r\nusing Foundation;\r\nusing UIKit;\r\n\r\nnamespace Demo\r\n{\r\n    public partial class ModernHttpClientMemoryLeakViewController : UIViewController\r\n    {\r\n        static bool UserInterfaceIdiomIsPhone\r\n        {\r\n            get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }\r\n        }\r\n\r\n        public ModernHttpClientMemoryLeakViewController(IntPtr handle)\r\n            : base(handle)\r\n        {\r\n        }\r\n\r\n        public override void DidReceiveMemoryWarning()\r\n        {\r\n            // Releases the view if it doesn't have a superview.\r\n            base.DidReceiveMemoryWarning();\r\n\t\t\t\r\n            // Release any cached data, images, etc that aren't in use.\r\n        }\r\n\r\n        #region View lifecycle\r\n\r\n        public override void ViewDidLoad()\r\n        {\r\n            base.ViewDidLoad();\r\n\t\t\t\r\n            // Perform any additional setup after loading the view, typically from a nib.\r\n            this.MyButton.TouchUpInside += async (object sender, EventArgs e) => \r\n            {\r\n                var contents = await this.GetFeedPage(new Uri(\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_day.geojson\"));\r\n                System.Diagnostics.Debug.WriteLine(contents);\r\n                contents = null;\r\n            };\r\n        }\r\n\r\n        public override void ViewWillAppear(bool animated)\r\n        {\r\n            base.ViewWillAppear(animated);\r\n        }\r\n\r\n        public override void ViewDidAppear(bool animated)\r\n        {\r\n            base.ViewDidAppear(animated);\r\n        }\r\n\r\n        public override void ViewWillDisappear(bool animated)\r\n        {\r\n            base.ViewWillDisappear(animated);\r\n        }\r\n\r\n        public override void ViewDidDisappear(bool animated)\r\n        {\r\n            base.ViewDidDisappear(animated);\r\n        }\r\n\r\n        private async Task<HttpResponseMessage> GetAsync(HttpClient client, Uri uri)\r\n        {\r\n            return await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);\r\n        }\r\n\r\n        private async Task<string> GetFeedPage(Uri uri)\r\n        {\r\n            using (var client = new HttpClient(new ModernHttpClient.NativeMessageHandler()))\r\n            using (var response = await this.GetAsync(client, uri))\r\n            {\r\n                if (response.StatusCode == HttpStatusCode.NotFound)\r\n                {\r\n                    return null;\r\n                }\r\n                else\r\n                {\r\n                    response.EnsureSuccessStatusCode();\r\n\r\n                    return await response.Content.ReadAsStringAsync();\r\n                }\r\n            }\r\n        }\r\n\r\n        #endregion\r\n    }\r\n}"}}