我正在创建FlickrImage类的实例,解析Flickr API照片响应。这个类有,做另一个API调用来获取地理定位的方法的getLocation:ObjC委托方法永远不会被调用
NSLog(@"getting location for %i",self.ID);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
OFFlickrAPIRequest *flickrAPIRequest = [[OFFlickrAPIRequest alloc] initWithAPIContext[appDelegate sharedDelegate].flickrAPIContext];
[flickrAPIRequest setDelegate:self];
NSString *flickrAPIMethodToCall = @"flickr.photos.geo.getLocation";
NSDictionary *requestArguments = [[NSDictionary alloc] initWithObjectsAndKeys:FLICKR_API_KEY,@"api_key",self.ID,@"photo_id",nil];
[flickrAPIRequest callAPIMethodWithGET:flickrAPIMethodToCall arguments:requestArguments];
[pool release];
我已经实现,将赶上来自API的响应,并与地理定位数据更新FlickrImage实例的回调方法 - 但它从来没有被调用。下面是其中的情况下获得创建:
NSDictionary *photosDictionary = [inResponseDictionary valueForKeyPath:@"photos.photo"];
NSDictionary *photoDictionary;
FlickrImage *flickrImage;
for (photoDictionary in photosDictionary) {
flickrImage = [[FlickrImage alloc] init];
flickrImage.thumbnailURL = [[appDelegate sharedDelegate].flickrAPIContext photoSourceURLFromDictionary:photoDictionary size:OFFlickrThumbnailSize];
flickrImage.hasLocation = TRUE; // TODO this is actually to be determined...
flickrImage.ID = [NSString stringWithFormat:@"%@",[photoDictionary valueForKeyPath:@"id"]];
flickrImage.owner = [photoDictionary valueForKeyPath:@"owner"];
flickrImage.title = [photoDictionary valueForKeyPath:@"title"];
[self.flickrImages addObject:[flickrImage retain]];
[flickrImage release];
[photoDictionary release];
}
的retain
是那里,因为我认为这可能有助于解决这一点,但它没有 - 也确实不是NSMutableArray里(flickrImages是NSMutableArray的)反正保留其成员?
编辑我应该补充的是,getLocation
方法(第一代码段)在一个线程被推出: [NSThread detachNewThreadSelector:@selector(的getLocation)toTarget:自withObject:无];
您应该删除for循环中额外的'retain'调用。该数组确实保留其成员,所以您基本上正在创建内存泄漏。 – benzado 2009-12-11 20:26:41