Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于linkedmap中的字典处理问题 #161

Open
leidi0129 opened this issue May 25, 2022 · 0 comments
Open

关于linkedmap中的字典处理问题 #161

leidi0129 opened this issue May 25, 2022 · 0 comments

Comments

@leidi0129
Copy link

leidi0129 commented May 25, 2022

删除节点的代码中_dic似乎是想要持有所有的Node,在队列中释放。

Node节点也注释说不持有前后节点,交给字典管理。

但是Map中的字典在赋值的时候用的却是__bridge,不转交对象管辖权,那么字典中的value应该无法持有Node节点才对?

@interface _YYLinkedMapNode : NSObject {
    @package
    __unsafe_unretained _YYLinkedMapNode *_prev; // retained by dic
    __unsafe_unretained _YYLinkedMapNode *_next; // retained by dic
...
}
@end
...
- (void)insertNodeAtHead:(_YYLinkedMapNode *)node {
    CFDictionarySetValue(_dic, (__bridge const void *)(node->_key), (__bridge const void *)(node));
   ...
}
- (void)removeAll {
     ...
    if (CFDictionaryGetCount(_dic) > 0) {
        CFMutableDictionaryRef holder = _dic;
        _dic = CFDictionaryCreateMutable(CFAllocatorGetDefault(), 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
        
        if (_releaseAsynchronously) {
            dispatch_queue_t queue = _releaseOnMainThread ? dispatch_get_main_queue() : YYMemoryCacheGetReleaseQueue();
            dispatch_async(queue, ^{
                CFRelease(holder); // hold and release in specified queue
            });
        }
       ...
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant