Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6831957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:47:59+00:00 2026-05-26T22:47:59+00:00

I’ve been trying to get rid of memory leaks in mapview. I am using

  • 0

I’ve been trying to get rid of memory leaks in mapview. I am using custom map pin class.
Everything works, but problem is – I need to filter mapview results. when i remove all mapview annotations – and add filtered results – performance tool finds leaks. but in this mapPin class I am using are used autorelease, so they should be released, but they aren’t. what am I doing wrong?

MapPin.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKMapView.h>
#import <MapKit/MKAnnotation.h>

@interface MapPin : NSObject<MKAnnotation> {
    CLLocationCoordinate2D coordinate;
    NSString * picture;
    NSInteger tag_number;
}

@property (nonatomic,assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;


- (id) initWithCoordinate:(CLLocationCoordinate2D) coord;
- (id) initWithCoordinate:(CLLocationCoordinate2D) coord title:(NSString *) title;
- (id) initWithCoordinate:(CLLocationCoordinate2D) coord title:(NSString *) title subtitle:(NSString *) subtitle;
- (id) initWithCoordinate:(CLLocationCoordinate2D) coord title:(NSString *) title subtitle:(NSString *) subtitle image:(NSString *) pic;
- (id) initWithCoordinate:(CLLocationCoordinate2D) coord title:(NSString *) title subtitle:(NSString *) subtitle image:(NSString *) pic num:(NSInteger) number;
- (void) setPic:(NSString *) picture;
- (NSString* ) getPic;

- (void) setNum:(NSInteger) tag_number;
- (NSInteger ) getNum;

@end

MapPin.m

#import "MapPin.h"


@implementation MapPin

@synthesize coordinate = _coordinate;
@synthesize title = _title;
@synthesize subtitle = _subtitle;


- (id) initWithCoordinate:(CLLocationCoordinate2D) coord
{
    return [self initWithCoordinate:coord title:@""];
}

- (id) initWithCoordinate:(CLLocationCoordinate2D) coord title:(NSString *) title {
    return [self initWithCoordinate:coord title:title subtitle:@""];

}
- (id) initWithCoordinate:(CLLocationCoordinate2D) coord title:(NSString *) title subtitle:(NSString *) subtitle {
    return [self initWithCoordinate:coord title:title subtitle:subtitle image:@""];}

- (id) initWithCoordinate:(CLLocationCoordinate2D) coord title:(NSString *) title subtitle:(NSString *) subtitle image:(NSString *) pic{
    MapPin * me = [[[MapPin alloc] init] autorelease];
    me.coordinate = coord;
    me.title = title;
    me.subtitle = subtitle;

    [me setPic:pic];

    return me;
}

- (id) initWithCoordinate:(CLLocationCoordinate2D) coord title:(NSString *) title subtitle:(NSString *) subtitle image:(NSString *) pic num:(NSInteger) number{
    MapPin * me = [[[MapPin alloc] init] autorelease];
    me.coordinate = coord;
    me.title = title;
    me.subtitle = subtitle;

    [me setPic:pic];
    [me setNum:number];
    return me;
}

- (void) setPic:(NSString*) pic {
    picture = pic;
}

- (NSString * ) getPic{
    return picture;
}

- (void) setNum:(NSInteger) number {
    tag_number = number;

}

- (NSInteger ) getNum{
    return tag_number;
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:48:00+00:00Added an answer on May 26, 2026 at 10:48 pm

    I have been using cutom map pin created by Mayur Birari, which i tweaked a little bit, to support custom map pin images and id’s.

    CustomMapPin.h

    #import <Foundation/Foundation.h>
    #import <MapKit/MapKit.h>
    
    @interface CustomMapPin : NSObject<MKAnnotation> {
    
        CLLocationCoordinate2D  coordinate;
        NSString*               title;
        NSString*               subtitle;
    
        NSString*               pic;
        NSInteger               tag_number;
    
    }
    
    @property (nonatomic, assign)   CLLocationCoordinate2D  coordinate;
    @property (nonatomic, copy)     NSString*               title;
    @property (nonatomic, copy)     NSString*               subtitle;
    @property (nonatomic, copy)     NSString*               pic;
    @property (nonatomic)           NSInteger               tag_number;
    
    
    @end
    

    CustomMapPin.m

    #import "CustomMapPin.h"
    
    
    @implementation CustomMapPin
    
    @synthesize title;
    @synthesize subtitle;
    @synthesize coordinate;
    @synthesize pic;
    @synthesize tag_number;
    
    
    - (void)dealloc 
    {
        self.title = nil;
        self.pic = nil;
        self.subtitle = nil;
        [super dealloc];
    }
    
    @end
    

    and using it in class like this:

    CLLocationCoordinate2D pinlocation;
    

    in a loop I set up required values and create a map pin:

    pinlocation.latitude = ...;
    
    pinlocation.longitude = ...;
    
    NSInteger pinID = ....;
    
    
    CustomMapPin* customMapPin=[[CustomMapPin alloc] init];
    
    customMapPin.coordinate=(CLLocationCoordinate2D
        {pinlocation.latitude,pinlocation.longitude};
    
    customMapPin.title=@"title";
    
    customMapPin.subtitle=@"subtitle";
    
    customMapPin.pic = @"customImageName";
    
    customMapPin.tag_number = pinId;
    
    
    [mapView addAnnotation:customMapPin];
    

    Setting up custom image:

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
    {
        if ([annotation isKindOfClass: [CustomMapPin class]]) 
        {
            CustomMapPin * a = annotation;
    
            [annView setImage:[UIImage imageNamed:a.pic]];
        }
    }
    

    Getting pin id on callout:

    - (void)mapView:(MKMapView *)mp annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    {
        CustomMapPin * v = (CustomMapPin *) view.annotation;
    
       int tagNumber = v.tag_number;
    
       ....
    }
    

    and finally – in my project It was required to have filter buttons – so I needed to remove all pins, and add required. By default calling mapview to remove all annotations created memory leaks. So when I need to clear mapview from annotations, I call this function:

    - (void)removeAnnotations
    {
        NSMutableArray *toRemove = [NSMutableArray arrayWithCapacity:[mapView.annotations count]];
    
        for (id annotation in mapView.annotations)
        {
            if (annotation != mapView.userLocation)
            {
                [toRemove addObject:annotation];
            }
        }
    
        [mapView removeAnnotations:toRemove];
    
        for(int i = 0; i < [toRemove count]; i++)
        {
            CustomMapPin * a = [toRemove objectAtIndex:i];
    
            [a release];
    
            a = nil;
        }
    }
    

    Hope this helps
    Happy coding! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.