RacTestScheduler
用CFBinaryHeapRef存储RACTestSchedulerAction
RACTestSchedulerAction是对 date, block, disposable的封装。
使用CFBinaryHeapAddValue方法把action写入。
使用CFBinaryHeapGetMinimumIfPresent 方法把action取出。
CFBinaryHeapCallBacks callbacks = (CFBinaryHeapCallBacks){
.version = 0,
.retain = &RACRetainScheduledAction,
.release = &RACReleaseScheduledAction,
.copyDescription = &CFCopyDescription,
.compare = &RACCompareScheduledActions
};
_scheduledActions = CFBinaryHeapCreate(NULL, 0, &callbacks, NULL);
static CFComparisonResult RACCompareScheduledActions(const void *ptr1, const void *ptr2, void *info) {
RACTestSchedulerAction *action1 = (__bridge id)ptr1;
RACTestSchedulerAction *action2 = (__bridge id)ptr2;
return CFDateCompare((__bridge CFDateRef)action1.date, (__bridge CFDateRef)action2.date, NULL);
}
是按照date的顺序出队列的。
也许取出有序性,是使用该结构的原因~~
1、问题1
不改变对象所有权。actionPtr拿到之后,并没有保持强引用,然后立即调用CFBinaryHeapRemoveMinimumValue将actionPtr从CFBinaryHeapRef中删除,这样后面actionPtr不就是野指针了吗?
const void *actionPtr = NULL;
if (!CFBinaryHeapGetMinimumIfPresent(self.scheduledActions, &actionPtr)) break;
//不改变对象所有权。actionPtr拿到之后,并没有保持强引用,然后立即调用CFBinaryHeapRemoveMinimumValue将actionPtr从CFBinaryHeapRef中删除,这样后面actionPtr不就是野指针了吗?
RACTestSchedulerAction *action = (__bridge id)actionPtr;
CFBinaryHeapRemoveMinimumValue(self.scheduledActions);
if (action.disposable.disposed) continue;
2、c类型 用assign
assign不改变对象引用计数
///assign不改变对象引用计数
@property (nonatomic, assign, readonly) CFBinaryHeapRef scheduledActions;
dealloc中需要释放