English 中文(简体)
Memory Leak when using for(object in array) with iPhone SDK
原标题:

I am running into some serious memory leaks in one of my applications I am building. I have a UINavigatonController that is inside a UITabBarview. Inside the NavView is a MKMap view. When you click an accessory button on a callout a detail view is loaded. In that detail view I am trying to populate a table from a plist using a for(object in array) loop. The plist is an array of dictionaries. I am running though the dictionaries to find one with a key that is the title of the callout and then get an array from inside that dictionary. It all works fine in the simulaor but I am getting massive memory leaks doing it the way I am. Any Idea whats going on?

     - (void)viewDidLoad {
        self.title = @"Route Details";
        NSString *path = [[NSBundle mainBundle] pathForResource:@"stopLocation" ofType:@"plist"];
        holderArray  = [[NSMutableArray alloc] initWithContentsOfFile:path];
        [self getRouteArray];
        routeDetails.delegate = self;
        routeDetails.dataSource = self;

    }
    -(void)getRouteArray{

        for (NSMutableDictionary *dictionary in holderArray) {
            //NSString *stopName = [dictionary objectForKey:@"StopName"];
            //NSString *stopName = [[NSString alloc] initWithString:[dictionary objectForKey:@"StopName"]];

            BOOL testString = [currentRoute isEqualToString:[dictionary objectForKey:@"StopName"]];

            if (testString) {
                routeArray = [[NSMutableArray alloc] initWithArray:[dictionary objectForKey:@"RouteService"]];
            }
        }
    }
- (void)dealloc {

    [routeArray release];
    [routeDetails release];

    [super dealloc];
}

holderArray is an ivar and so is route array. As you can see I have tried a few ways of allocating the nstrings and arrays but all seem to yield the same leaks. According to the performance tool I am leaking from NSCFString, NSCFDictionary, and the NSCFArry. I released the routeArray in the dealloc and it works fine, but if I release holderArray it crashes whenever I go back to my map from the detail view. I guess I am just really unsure as to how to deal with the strings and dictionary used in the for loop.

Just to add the detail view is being created like so:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{


    NSString *selectedRouteName = [NSString stringWithFormat:@"%@",view.annotation.title];

    RouteDetailView *rdc = [[RouteDetailView alloc] initWithNibName:@"RouteDetailView" bundle:nil];
    [rdc setCurrentRoute:selectedRouteName];
    [self.navigationController pushViewController:rdc animated:YES];
    [rdc release];


}

Sorry if any of the above is unclear. Let me know and I can try to rephrase it.

最佳回答

Will testString be true for at most one key in holderArray? If so, you should probably break out of the loop after setting routeArray. If not, then you may be setting routeArray multiple times, and all but the last array you assigned to it would be leaked.

Also, I don t see you releasing holderArray.

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签