From 4e68935e3f3be2afec9ad0ea9ec00aae9a8ce287 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 22 Oct 2020 16:37:43 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20Fix=20Memory=20Leak=20Issue=20-=20A?= =?UTF-8?q?dd=20dispose=20scenarios=20for=20HttpCleint=20-=20Add=20using?= =?UTF-8?q?=20scope=20for=20StringContent=20&=20HttpResponseMessage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PushSharp.Google/GcmServiceConnection.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/PushSharp.Google/GcmServiceConnection.cs b/PushSharp.Google/GcmServiceConnection.cs index b3b539c5..0308b950 100644 --- a/PushSharp.Google/GcmServiceConnection.cs +++ b/PushSharp.Google/GcmServiceConnection.cs @@ -53,14 +53,14 @@ public async Task Send (GcmNotification notification) { var json = notification.GetJson (); - var content = new StringContent (json, System.Text.Encoding.UTF8, "application/json"); - - var response = await http.PostAsync (Configuration.GcmUrl, content); - - if (response.IsSuccessStatusCode) { - await processResponseOk (response, notification).ConfigureAwait (false); - } else { - await processResponseError (response, notification).ConfigureAwait (false); + using (var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json")) + using (var response = await http.PostAsync(Configuration.GcmUrl, content)) + { + if (response.IsSuccessStatusCode) { + await processResponseOk(response, notification).ConfigureAwait(false); + } else { + await processResponseError(response, notification).ConfigureAwait(false); + } } } @@ -212,5 +212,10 @@ static GcmResponseStatus GetGcmResponseStatus (string str) //Default return GcmResponseStatus.Error; } + + ~GcmServiceConnection() + { + http.Dispose(); + } } }