ios - 我应该在哪里释放组队列?

标签 ios objective-c memory-management grand-central-dispatch

我的代码中有这个:

- (void)loadPanoramaForLocation:(CLLocation *)location
{
    dispatch_group_t group = dispatch_group_create();
...
    dispatch_group_enter(group);
    [self getImageForPanorama:model level:level face:PLCubeFaceOrientationFront completion:^(PLImage * image) {
        if (image) {
            [cubicPanorama setTexture:[PLTexture textureWithImage:image] face: PLCubeFaceOrientationFront];
            dispatch_group_leave(group);
        }
    }];
...
    dispatch_group_enter(group);
    [self getImageForPanorama:model level:level face:PLCubeFaceOrientationBack completion:^(PLImage * image) {
        if (image) {
            [cubicPanorama setTexture:[PLTexture textureWithImage:image] face: PLCubeFaceOrientationBack];
            dispatch_group_leave(group);
        }
    }];
...
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        dispatch_release(group);
        NSObject<PLIPanorama> *panorama = cubicPanorama;
        [plView setPanorama:panorama];
    });
}

我没有在这段代码中使用 ARC,我想知道,这里使用 dispatch_release 的方法是否正确?我应该把它放在哪里?放在dispatch_group_notify里可以吗?谢谢

最佳答案

您可以在 -loadPanoramaForLocation: 中将其作为最后一件事发布。 dispatch_group_notify() 被记录为保留它直到通知 block 运行完成。所以,一旦你调用了它,就没有必要保留你的强引用。

关于ios - 我应该在哪里释放组队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25131322/

相关文章:

ios - 环球银行金融电信协会 : Convert String from XLM to NSDate

objective-c - NSObject 描述和 debugDescription

objective-c - iPhone 4 iOS 在没有 NavBar 和 TabBar 的情况下截取 View ?

performance - 可分配数组性能

memory-management - 段的静态重定位或静态重定位是什么意思

ios - Safari 不触发触摸事件

ios - 对两个项目使用水平滚动时右对齐 UICollectionView(对于 RTL)

python - 使用名为 guppy ( heapy ) 的 Python 工具时 C 代码中的段错误

ios - iPhone 6 plus 真机 UIScreen mainScreen 大小奇怪

cocos2d-iphone - 如何仅在选定的源文件(Xcode)中将警告视为错误?