From ba7b66b83a83328f56e0676efcff5d3c553ac6bf Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Thu, 12 Jan 2017 14:43:57 -0700 Subject: Fix out-of-memory crashes on iOS when creating maps (#467) * Pool map views on iOS 10 to avoid memory issues Clean up disposal implementation for map renderer, delegate * Enable 39489 test on iOS * Add missing XF Maps references * Add missing maps reference to Windows 8.1 project * Actually enable the test for iOS * Fix placement of Isolate override * Don't create a new control for ImageRenderer if NewElement is null * Reverting fixes to ViewRenderer Dispose; have to fix that in a separate PR --- Xamarin.Forms.Maps.iOS/MapPool.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Xamarin.Forms.Maps.iOS/MapPool.cs (limited to 'Xamarin.Forms.Maps.iOS/MapPool.cs') diff --git a/Xamarin.Forms.Maps.iOS/MapPool.cs b/Xamarin.Forms.Maps.iOS/MapPool.cs new file mode 100644 index 00000000..dc8a9c47 --- /dev/null +++ b/Xamarin.Forms.Maps.iOS/MapPool.cs @@ -0,0 +1,25 @@ +using System.Collections.Concurrent; +using MapKit; + +namespace Xamarin.Forms.Maps.iOS +{ + // A static pool of MKMapView instances we can reuse + internal class MapPool + { + static MapPool s_instance; + public static MapPool Instance => s_instance ?? (s_instance = new MapPool()); + + internal readonly ConcurrentQueue Maps = new ConcurrentQueue(); + + public static void Add(MKMapView mapView) + { + Instance.Maps.Enqueue(mapView); + } + + public static MKMapView Get() + { + MKMapView mapView; + return Instance.Maps.TryDequeue(out mapView) ? mapView : null; + } + } +} \ No newline at end of file -- cgit v1.2.3