summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-01-16 12:36:49 -0700
committerRui Marinho <me@ruimarinho.net>2017-01-16 19:36:49 +0000
commit5fec30f288fffd6ad7c11a0557c809f3befdd79a (patch)
tree122afcc742a7546169df9bf16c204de76955e24b
parentec8bcd443a20d79f06bc2de1ba6b463c03f63d47 (diff)
downloadxamarin-forms-5fec30f288fffd6ad7c11a0557c809f3befdd79a.tar.gz
xamarin-forms-5fec30f288fffd6ad7c11a0557c809f3befdd79a.tar.bz2
xamarin-forms-5fec30f288fffd6ad7c11a0557c809f3befdd79a.zip
Pool and reuse MKMapView instances on iOS 9 as well as iOS 10 (#680)
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39489.cs4
-rw-r--r--Xamarin.Forms.Core.iOS.UITests/UITestCategories.cs1
-rw-r--r--Xamarin.Forms.Maps.iOS/FormsMaps.cs11
-rw-r--r--Xamarin.Forms.Maps.iOS/MapRenderer.cs14
4 files changed, 23 insertions, 7 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39489.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39489.cs
index 0e04fcd5..622a5f4b 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39489.cs
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39489.cs
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Xamarin.Forms.Maps;
#if UITEST
+using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif
@@ -14,6 +15,9 @@ using NUnit.Framework;
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
+#if UITEST
+ [Category(UITestCategories.Maps)]
+#endif
[Issue(IssueTracker.Bugzilla, 39489, "Memory leak when using NavigationPage with Maps", PlatformAffected.Android | PlatformAffected.iOS)]
public class Bugzilla39489 : TestNavigationPage
{
diff --git a/Xamarin.Forms.Core.iOS.UITests/UITestCategories.cs b/Xamarin.Forms.Core.iOS.UITests/UITestCategories.cs
index dbc298f6..28a6fff4 100644
--- a/Xamarin.Forms.Core.iOS.UITests/UITestCategories.cs
+++ b/Xamarin.Forms.Core.iOS.UITests/UITestCategories.cs
@@ -29,6 +29,7 @@
public const string TimePicker = "TimePicker";
public const string ToolbarItem = "ToolbarItem";
public const string WebView = "WebView";
+ public const string Maps = "Maps";
public const string ManualReview = "ManualReview";
}
diff --git a/Xamarin.Forms.Maps.iOS/FormsMaps.cs b/Xamarin.Forms.Maps.iOS/FormsMaps.cs
index 19c0701e..a87cb8dc 100644
--- a/Xamarin.Forms.Maps.iOS/FormsMaps.cs
+++ b/Xamarin.Forms.Maps.iOS/FormsMaps.cs
@@ -7,6 +7,7 @@ namespace Xamarin
{
static bool s_isInitialized;
static bool? s_isiOs8OrNewer;
+ static bool? s_isiOs9OrNewer;
static bool? s_isiOs10OrNewer;
internal static bool IsiOs8OrNewer
@@ -19,6 +20,16 @@ namespace Xamarin
}
}
+ internal static bool IsiOs9OrNewer
+ {
+ get
+ {
+ if (!s_isiOs9OrNewer.HasValue)
+ s_isiOs9OrNewer = UIDevice.CurrentDevice.CheckSystemVersion(9, 0);
+ return s_isiOs9OrNewer.Value;
+ }
+ }
+
internal static bool IsiOs10OrNewer
{
get
diff --git a/Xamarin.Forms.Maps.iOS/MapRenderer.cs b/Xamarin.Forms.Maps.iOS/MapRenderer.cs
index cc9f2533..794a4a04 100644
--- a/Xamarin.Forms.Maps.iOS/MapRenderer.cs
+++ b/Xamarin.Forms.Maps.iOS/MapRenderer.cs
@@ -137,13 +137,13 @@ namespace Xamarin.Forms.Maps.iOS
return Control.GetSizeRequest(widthConstraint, heightConstraint);
}
- // iOS 10 has some issues with releasing memory from map views; each one we create allocates
+ // iOS 9/10 have some issues with releasing memory from map views; each one we create allocates
// a bunch of memory we can never get back. Until that's fixed, we'll just reuse MKMapViews
// as much as possible to prevent creating new ones and losing more memory
// For the time being, we don't want ViewRenderer handling disposal of the MKMapView
- // if we're on iOS 10; during Dispose we'll be putting the MKMapView in a pool instead
- protected override bool ManageNativeControlLifetime => !FormsMaps.IsiOs10OrNewer;
+ // if we're on iOS 9 or 10; during Dispose we'll be putting the MKMapView in a pool instead
+ protected override bool ManageNativeControlLifetime => !FormsMaps.IsiOs9OrNewer;
protected override void Dispose(bool disposing)
{
@@ -170,14 +170,14 @@ namespace Xamarin.Forms.Maps.iOS
mkMapView.Delegate = null;
mkMapView.RemoveFromSuperview();
- if (FormsMaps.IsiOs10OrNewer)
+ if (FormsMaps.IsiOs9OrNewer)
{
// This renderer is done with the MKMapView; we can put it in the pool
// for other rendererers to use in the future
MapPool.Add(mkMapView);
}
- // For iOS versions < 10, the MKMapView will be disposed in ViewRenderer's Dispose method
+ // For iOS versions < 9, the MKMapView will be disposed in ViewRenderer's Dispose method
if (_locationManager != null)
{
@@ -208,7 +208,7 @@ namespace Xamarin.Forms.Maps.iOS
{
MKMapView mapView = null;
- if (FormsMaps.IsiOs10OrNewer)
+ if (FormsMaps.IsiOs9OrNewer)
{
// See if we've got an MKMapView available in the pool; if so, use it
mapView = MapPool.Get();
@@ -216,7 +216,7 @@ namespace Xamarin.Forms.Maps.iOS
if (mapView == null)
{
- // If this is iOS 9 or lower, or if there weren't any MKMapViews in the pool,
+ // If this is iOS 8 or lower, or if there weren't any MKMapViews in the pool,
// create a new one
mapView = new MKMapView(RectangleF.Empty);
}