AddObject NSMutableArray mit malloc'd struct

Ich habe Probleme mit einem Codeausschnitt. Ich versuche, mit der addObject-Methode eine Instanz von CLLocationCoordinate2D zu einem NSMutable-Array hinzuzufügen, aber wann immer die Zeile ausgeführt wird, stürzt meine App ab. Stimmt etwas mit diesem Code nicht?

Der Absturz ist in dieser Zeile:

[points addObject:(id)new_coordinate];

Polygon.m:

#import "Polygon.h"

@implementation Polygon
@synthesize points;

- (id)init {
    self = [super init];
    if(self) {
        points = [[NSMutableArray alloc] init];
    }
    return self;
}


-(void)addPointLatitude:(double)latitude Longitude:(double)longitude {
    NSLog(@"Adding Coordinate: [%f, %f] %d", latitude, longitude, [points count]);
    CLLocationCoordinate2D* new_coordinate = malloc(sizeof(CLLocationCoordinate2D));
    new_coordinate->latitude = latitude;
    new_coordinate->longitude = longitude;
    [points addObject:(id)new_coordinate];
    NSLog(@"%d", [points count]);
}


-(bool)pointInPolygon:(CLLocationCoordinate2D*) p {
    return true;
}


-(CLLocationCoordinate2D*) getNEBounds {
    ...
}

-(CLLocationCoordinate2D*) getSWBounds {
    ...
}


-(void) dealloc {
    for(int count = 0; count < [points count]; count++) {
        free([points objectAtIndex:count]);
    }

    [points release];
    [super dealloc];
}

@end

Antworten auf die Frage(3)

Ihre Antwort auf die Frage