gpt4 book ai didi

ios - 是否可以将dispatch_queue_t添加到NSMutableArray?

转载 作者:行者123 更新时间:2023-12-01 16:45:42 26 4
gpt4 key购买 nike

我正在尝试将dispatch_queue_t添加到NSMutableArray中,如下所示:

    NSMutableArray* queuesWaitingForTargetQueue = (__bridge NSMutableArray*)dispatch_queue_get_specific(targetQueue, WAITING_QUEUE_LIST_KEY);

NSLog(@" dispatch_get_current_queue() = %#x", (unsigned int)dispatch_get_current_queue());
NSLog(@" dispatch_get_main_queue() = %#x", (unsigned int)dispatch_get_main_queue());
NSLog(@" currQueueId = %#x", (unsigned int)currQueueId);
NSLog(@" queuesWaitingForTargetQueue = %#x (%@)", (unsigned int)queuesWaitingForTargetQueue, NSStringFromClass([queuesWaitingForTargetQueue class]));

[queuesWaitingForTargetQueue addObject:(__bridge id)currQueueId];

最后一行有时会因EXC_BAD_ACCESS而失败:
Thread 1: EXC_BAD_ACCESS (code=1, address=0xc08314eb)

输出为:
 dispatch_get_current_queue() = 0x2879640
dispatch_get_main_queue() = 0x2879640
currQueueId = 0x2879640
queuesWaitingForTargetQueue = 0x8672ae0 (__NSArrayM)

这有什么问题吗?

最佳答案

您的内存管理在这里将是一个真正的问题-崩溃几乎可以肯定是指向先前发布的对象的指针。如果确实需要移动数组,则使用高级桥强制转换(CFBridging ...)从id到CFType(如CFMutableDictionary)来回移动数组,然后使用CF对象作为键。完成后,CFR释放CF对象。

关于ios - 是否可以将dispatch_queue_t添加到NSMutableArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20130551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com