Ich arbeite an einer iPhone App Zeichnung Overlays auf einer Karte. Ich mag die Arrays speichern, die die Overlays in einem NSMutableDictionary enthalten, aber nur den letzten Eintrag ich gerettet Werke:NSMutableDictionary Memory Problem
// Get "Kurwege" from CoreData
NSError * error;
if(![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]); // TODO
}
if(self.overlaysDictionary == nil) {
self.overlaysDictionary = [[NSMutableDictionary alloc] initWithCapacity:[fetchedResultsController.fetchedObjects count]];
}
NSString *path;
for (Kurweg *kurweg in fetchedResultsController.fetchedObjects) {
// Locate the path to the .kml file in the application's bundle
// and parse it with the KMLParser.
path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@", [[kurweg valueForKey:@"kmlfile"] description]] ofType:@"kml"];
kml = [[KMLParser parseKMLAtPath:path] retain]; // PROBLEM: Executing this the second time seems to override my data stored in the dictionary
// Save overlays in dictionary
[self.overlaysDictionary setObject:[kml overlays] forKey:[NSString stringWithFormat:@"%@", [[kurweg valueForKey:@"kmlfile"] description]]];
}
// Draw overlays
NSArray *keys = [overlaysDictionary allKeys];
for (NSString *key in keys) {
// Add all of the MKOverlay objects parsed from the KML file to the map.
[map addOverlays:[overlaysDictionary objectForKey:key]];
}
Offensichtlich ist es ein Speicherproblem, aber leider weiß ich nicht, wie die Daten behalten gespeichert im Wörterbuch. Diese
ist ein Auszug aus dem Code in dem KML-Parser, genommen von einem Apple-Beispiel:
- (NSArray *)overlays {
NSMutableArray *overlays = [[NSMutableArray alloc] init];
for (KMLPlacemark *placemark in _placemarks) {
id <MKOverlay> overlay = [placemark overlay];
if (overlay)
[overlays addObject:overlay];
}
return [overlays autorelease];
}
Vielen Dank im Voraus!
Wo und wie ist die Variable 'kml' definiert? – dreamlax
Die kml-Variable ist in der Header-Datei definiert: KMLParser * kml; Wenn möglich, möchte ich nicht den gesamten Parser speichern, sondern nur die Ausgabe (NSArray overlay) – sqeez3r
Mindestens ein Leck tritt auf, wenn ich diesen Code durchlaufe. Könnte das das Problem sein? – sqeez3r