PDA

View Full Version : iOS. Big memory usage after adding many annotations



Hibari
13.11.2015, 15:33
Hello, i have installed SDK via Cocoapods, there are error in file SKRoutingservice.h

SDK trying to call function
-(void)zoomToRouteWithInsets:(UIEdgeInsets)insets;
but there are no such function, only
-(void)zoomToRouteWithInsets:(UIEdgeInsets)insets duration:(int)duration; available, so it won't compile. But it's not a main problem.

1) My task is to add custom annotations with custom views on map. How i do these see code below.

i'm trying to add 457 annotations. Device iPhone 5 simulator, iOS 8

for (NSUInteger i = 0; i<[self.fetchedResultController fetchedObjects].count; ++i) {
LandmarksPOI *landmark = [[self.fetchedResultController fetchedObjects] objectAtIndex:i];
SKAnnotation *annotation = [SKAnnotation annotation];
UIImageView *pinView = [[UIImageView alloc] init];
pinView.frame = CGRectMake(0, 0, 37, 66);
pinView.image = [UIImage imageNamed:@"pin_g"];
SKAnnotationView *view = [[SKAnnotationView alloc] initWithView:pinView reuseIdentifier:@"uniId"];
annotation.annotationView = view;
annotation.identifier = [landmark.theId integerValue];
annotation.location = CLLocationCoordinate2DMake([landmark.address.latitude floatValue], [landmark.address.longitude floatValue]);
[self.mapView addAnnotation:annotation withAnimationSettings:[SKAnimationSettings animationSettings]];
}

After i add all annotations my app start using 516-518 mb of memory, or it's crash on device. What i'm doing wrong?
2) And how to group annotations when i zoom out map?

Thank you.

Hibari
13.11.2015, 16:14
okay, problem is in SKAnnotationView, if i don't set custom view my app use only ~200mb, not good but better then was, so how can i set custom annotation view without big memory usage?

Hibari
13.11.2015, 16:38
Magic, i optimise my code a little bit:


UIImageView *pinView = [[UIImageView alloc] init];
pinView.frame = CGRectMake(0, 0, 28, 50);
pinView.image = [UIImage imageNamed:@"pin_g"];
SKAnnotationView *view = [[SKAnnotationView alloc] initWithView:pinView reuseIdentifier:@"viewID"];
for (NSUInteger i = 0; i<[self.fetchedResultController fetchedObjects].count; ++i) {
LandmarksPOI *landmark = [[self.fetchedResultController fetchedObjects] objectAtIndex:i];
SKAnnotation *annotation = [SKAnnotation annotation];
annotation.annotationView = view;
annotation.annotationType = SKAnnotationTypeGreen;
annotation.identifier = [landmark.theId integerValue];
annotation.location = CLLocationCoordinate2DMake([landmark.address.latitude floatValue], [landmark.address.longitude floatValue]);
[self.mapView addAnnotation:annotation withAnimationSettings:nil];
}

all changes are useless, except of
pinView.frame = CGRectMake(0, 0, 28, 50); when i change image size memory usage decreased to 250 mb, still bad, help please :)

jimt2000
13.11.2015, 17:18
The subject title says big memory usage after adding many annotations.

1. How many annotations are you adding?
2. How much memory usage is there if you comment out the code that creates and adds the annotations?

That info might help provide some perspective to the problem.

Hibari
13.11.2015, 17:35
I update my post.
I'm trying to add 457 annotations now, but it may be more.
457 - use 516 mb with pinView size (37, 66)
457 - use 250 mb with pinView size (28, 50)

Thank you.

jimt2000
13.11.2015, 17:41
Do you know the memory usage if you comment out the code the creates and adds the annotations? What's the memory usage if you add 228 (half of 457) annotations?

I'm just wondering about the impact on memory of the annotations vs. the rest of the program.

Hibari
13.11.2015, 17:59
I'm also wondering about such usage i don't have any leaks, app without map use ~40mb, when i initialise map with API key in appDelegate memory usage grows to ~60mb, when i open controller with map and without annotations memory usage grows to ~170 mb.

jimt2000
13.11.2015, 19:50
Interesting. I'm seeing high memory usage also. When running on a iPad retina simulator, I see around 20MB increase when I had a pair of annotations (1 image--a pin, and one uiview). When I run on an iPad 2 simulator, I see about 4MB increase.