This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use a pair of NSSets to manage the retain/release lifecycle of layers. #11343
Closed
julianrex
wants to merge
6
commits into
gl-layer-memory-fix
from
jrex-custom-layer-style-changed-leak
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
22a1da5
[ios] Adding a few more test cases. testOpenGLLayerDoesNotLeakWhenSty…
0327167
[ios] Added sets to manage retain/release of layers (esp custom gl la…
6c9239c
[macos] Added retain/release calls to macos's MGLMapView cf. iOS.
ad323de
Merge branch 'gl-layer-memory-fix' into jrex-custom-layer-style-chang…
julianrex 6fb2a94
[ios, macos, core] Added retain/release manager that holds on to the …
bcdf230
[macos] Updated MGLMapView with new layer manager.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,10 @@ @interface MGLStyle() | |
@property (readonly, copy, nullable) NSURL *URL; | ||
@property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, NS_DICTIONARY_OF(NSObject *, MGLTextLanguage *) *) *localizedLayersByIdentifier; | ||
|
||
// Used for retain/release management | ||
@property (nonatomic) NSMutableSet *layersForUpdating; | ||
@property (nonatomic) NSSet *layersForRendering; | ||
|
||
@end | ||
|
||
@implementation MGLStyle | ||
|
@@ -172,6 +176,8 @@ + (NSURL *)trafficNightStyleURLWithVersion:(NSInteger)version { | |
|
||
- (instancetype)initWithRawStyle:(mbgl::style::Style *)rawStyle mapView:(MGLMapView *)mapView { | ||
if (self = [super init]) { | ||
_layersForUpdating = [NSMutableSet set]; | ||
|
||
_mapView = mapView; | ||
_rawStyle = rawStyle; | ||
_localizedLayersByIdentifier = [NSMutableDictionary dictionary]; | ||
|
@@ -534,6 +540,25 @@ - (void)insertLayer:(MGLStyleLayer *)layer aboveLayer:(MGLStyleLayer *)sibling { | |
[self didChangeValueForKey:@"layers"]; | ||
} | ||
|
||
#pragma mark - Layer retain/release management | ||
|
||
- (void)addToManagedLayers:(MGLStyleLayer*)layer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be invoked from |
||
[self.layersForUpdating addObject:layer]; | ||
} | ||
|
||
- (void)removeFromManagedLayers:(MGLStyleLayer*)layer { | ||
[self.layersForUpdating removeObject:layer]; | ||
} | ||
|
||
- (void)retainLayersUsedDuringRendering { | ||
self.layersForRendering = [self.layersForUpdating copy]; | ||
} | ||
|
||
- (void)releaseLayersUsedDuringRendering { | ||
self.layersForRendering = nil; | ||
} | ||
|
||
|
||
#pragma mark Style classes | ||
|
||
- (NS_ARRAY_OF(NSString *) *)styleClasses | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the use of these properties remove the need for tracking the peer object in core for style layers? For layers created in the SDK,
[MGLStlye layerFromMBGLLayer]
could be used to lookup this set instead of querying core