相关疑难解决方法(0)

修复警告"在此块中强烈捕获[某个对象]可能会导致启用ARC的代码中的保留周期"

在启用ARC的代码中,如何在使用基于块的API时修复有关潜在保留周期的警告?

警告:
Capturing 'request' strongly in this block is likely to lead to a retain cycle

由这段代码生成:

ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:...

[request setCompletionBlock:^{
    NSDictionary *jsonDictionary = [[CJSONDeserializer deserializer] deserialize:request.rawResponseData error:nil];
    // ...
    }];
Run Code Online (Sandbox Code Playgroud)

警告与request块内对象的使用相关联.

cocoa cocoa-touch retain asihttprequest automatic-ref-counting

140
推荐指数
4
解决办法
5万
查看次数

ASIHTTPRequest内存泄漏

我有一个iOS项目,我在自己的类中使用ARC,但在其他库中关闭了ARC ASIHTTPRequest.

我使用下面的代码从Web服务器获取图像时出现大量内存泄漏:

-(void)buildPhotoView {

self.photoLibView.hidden = NO;

NSString *assetPathStr = [self.cellData objectForKey:@"AssetThumbPath"];

// get the thumbnail image of the ocPHOTOALBUM from the server and populate the UIImageViews
NSURL *imageURL = [NSURL URLWithString:assetPathStr];

__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:imageURL];
__unsafe_unretained ASIHTTPRequest *weakRequest = request;
[weakRequest setCompletionBlock:^{

    // put image into imageView when request complete
    NSData *responseData = [weakRequest responseData];
    UIImage *photoAlbumImage = [[UIImage alloc] initWithData:responseData];
    self.photo1ImageView.image = photoAlbumImage;
}];
[weakRequest setFailedBlock:^{
    NSError *error = [request error];
    NSLog(@"error geting file: …
Run Code Online (Sandbox Code Playgroud)

objective-c asihttprequest ios

2
推荐指数
1
解决办法
2723
查看次数