summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2018-02-26 11:11:27 -0500
committerJulian Rex <julian.rex@mapbox.com>2018-02-26 11:11:27 -0500
commit43bcba4cbe2242d1c0aaefbdeed0906600589511 (patch)
treea2c3162a5823ac3c662484c7fe9d42c2d2c8562a
parentb07fda134777b3b82f64c4b39902158b11b47ae7 (diff)
downloadqtlocation-mapboxgl-upstream/jrex-gl-layer-memory-fix.tar.gz
[ios] Release only called if the layer is really being removed from the style. Update associated test that failed.upstream/jrex-gl-layer-memory-fix
-rw-r--r--platform/darwin/src/MGLStyleLayer.mm8
-rw-r--r--platform/darwin/test/MGLStyleTests.mm39
-rw-r--r--platform/ios/Integration Tests/MBGLIntegrationTests.m1
3 files changed, 35 insertions, 13 deletions
diff --git a/platform/darwin/src/MGLStyleLayer.mm b/platform/darwin/src/MGLStyleLayer.mm
index 2a70cab563..45a4486525 100644
--- a/platform/darwin/src/MGLStyleLayer.mm
+++ b/platform/darwin/src/MGLStyleLayer.mm
@@ -54,11 +54,11 @@
{
if (self.rawLayer == style.rawStyle->getLayer(self.identifier.UTF8String)) {
_pendingLayer = style.rawStyle->removeLayer(self.identifier.UTF8String);
- }
- // Pair the retain above, and release self, since we're now removed from the collection
- CFTypeRef toRelease = (__bridge CFTypeRef)self;
- CFBridgingRelease(toRelease);
+ // Pair the retain above, and release self, since we're now removed from the collection
+ CFTypeRef toRelease = (__bridge CFTypeRef)self;
+ CFBridgingRelease(toRelease);
+ }
}
- (void)setVisible:(BOOL)visible
diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm
index 8f610e338c..5ab17dd62e 100644
--- a/platform/darwin/test/MGLStyleTests.mm
+++ b/platform/darwin/test/MGLStyleTests.mm
@@ -359,20 +359,41 @@
}
- (void)testAddingLayerOfTypeABeforeRemovingLayerOfTypeBWithSameIdentifier {
- MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-identifier" shape:nil options:nil];
- [self.style addSource:source];
- // Add a fill layer
- MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"some-identifier" source:source];
- [self.style addLayer:fillLayer];
+ __weak MGLFillStyleLayer *weakFillLayer = nil;
+ __weak MGLLineStyleLayer *weakLineLayer = nil;
- // Attempt to remove a line layer with the same identifier as the fill layer
- MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:fillLayer.identifier source:source];
- [self.style removeLayer:lineLayer];
+ @autoreleasepool {
+
+ MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-identifier" shape:nil options:nil];
+ [self.style addSource:source];
+
+ // Add a fill layer
+ MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"some-identifier" source:source];
+ weakFillLayer = fillLayer;
+
+ [self.style addLayer:fillLayer];
- XCTAssertTrue([[self.style layerWithIdentifier:fillLayer.identifier] isMemberOfClass:[MGLFillStyleLayer class]]);
+ // Attempt to remove a line layer with the same identifier as the fill layer
+ MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:fillLayer.identifier source:source];
+ weakLineLayer = lineLayer;
+ [self.style removeLayer:lineLayer];
+
+ // The above remove should fail, and the fill layer should still be there.
+ XCTAssertTrue([[self.style layerWithIdentifier:fillLayer.identifier] isMemberOfClass:[MGLFillStyleLayer class]]);
+
+ // Finally remove the fill layer.
+ [self.style removeLayer:fillLayer];
+
+ fillLayer = nil;
+ lineLayer = nil;
+ }
+
+ XCTAssertNil(weakFillLayer, @"");
+ XCTAssertNil(weakLineLayer, @"");
}
+
- (NSString *)stringWithContentsOfStyleHeader {
NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL
URLByAppendingPathComponent:@"Headers" isDirectory:YES]
diff --git a/platform/ios/Integration Tests/MBGLIntegrationTests.m b/platform/ios/Integration Tests/MBGLIntegrationTests.m
index 941e73621f..1008ef6c9f 100644
--- a/platform/ios/Integration Tests/MBGLIntegrationTests.m
+++ b/platform/ios/Integration Tests/MBGLIntegrationTests.m
@@ -42,6 +42,7 @@
- (void)tearDown {
_styleLoadingExpectation = nil;
self.mapView = nil;
+ self.style = nil;
[super tearDown];
}