Tag: 保留循环

阻止和保留周期不能赶上它

我有一个块和弱引用的问题,我在ARC下。 我build立了一个类,它是一个免费的项目,是一个围绕Google Directions API的简单包装,你可以在这里下载: link to the project 我在视图控制器内使用它的问题是,使用它后,视图控制器不会被释放。 我想这是这个对象的问题,因为如果我注释掉或设置为零,一切正常。 我无法理解保留周期在哪里,当然我设置为弱自我,这里是我使用它的视图控制器的方法: – (void) getDirections{ __weak RouteMapViewController * weakSelf = self; self.routeObject = [[RouteDirectionsObject alloc]init]; [self.mapView removeAnnotations:self.mapView.annotations]; [self.mapView removeOverlays:self.mapView.overlays]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; [_routeObject createDirectionRequestWithStartPoint:weakSelf.startPoint andEndPoint:weakSelf.endPoint withCallBackBlock:^(NSError *error, NSDictionary *routeDistance, NSDictionary *routeDuration, MKPolyline *routePolyline, NSArray *routes, NSArray *steps, CLLocation *startPoint, CLLocation *endPoint, NSArray *directions) { [[UIApplication sharedApplication] […]

如果从块中调用的方法使用自我,我是否需要使用弱自我指针?

使用self. 在块中导致保留周期,所以我需要创build一个weakSelf的引用。 我明白这一点 但! 如果从我的块我调用一个方法,使用self “,这是否也导致保留周期?例​​如,如果我重新加载UITableView从一个块和我的一些UITableView委托方法我self.这是否意味着我必须到处传递这个薄弱的参考?

如何解决在这个区块强烈的“捕捉”区块可能会导致一个保留周期“

我正在处理这个代码,它在网上做了一些冗长的asynchronous操作,当它完成时,它会触发一个完成块,在那里执行一些testing,如果一个variables获得了一个特定的值,另一个冗长的操作应该立即开始: -(void) performOperation { void(^completionBlock) (id obj, NSError *err, NSURLRequest *request)= ^(id obj,NSError *err, NSURLRequest *request){ int variable=0; // Do completion operation A //… //… // Do completion operation B //Get the variable value if(variable>0){ [self doLengthyAsynchronousOperationWithCompletionBlock: completionBlock]; } }; //Perform the lenhgty operation with the above completionBlock [self doLengthyAsynchronousOperationWithCompletionBlock: completionBlock]; } -(void) doLengthyAsynchronousOperationWithCompletionBlock: completionBlock […]