相关疑难解决方法(0)

Objective-C中的递归块在ARC中泄漏

所以我正在使用递归块.我理解,对于要递归的块,它需要以__block关键字开头,并且必须将其复制,以便将其放在堆上.但是,当我这样做时,它显示为仪器中的泄漏.有谁知道为什么或如何绕过它?

请注意,在下面的代码中,我已经引用了许多其他块,但它们都不是递归的.

__block NSDecimalNumber *(^ProcessElementStack)(LinkedList *, NSString *) = [^NSDecimalNumber *(LinkedList *cformula, NSString *function){
        LinkedList *list = [[LinkedList alloc] init];
        NSDictionary *dict;
        FormulaType type;
        while (cformula.count > 0) {
            dict = cformula.pop;
            type = [[dict objectForKey:@"type"] intValue];
            if (type == formulaOperandOpenParen || type == formulaListOperand || type == formulaOpenParen) [list add:ProcessElementStack(cformula, [dict objectForKey:@"name"])];
            else if (type == formulaField || type == formulaConstant) [list add:NumberForDict(dict)];
            else if (type == formulaOperand) [list add:[dict objectForKey:@"name"]];
            else if (type == formulaCloseParen) {
                if (function){ …
Run Code Online (Sandbox Code Playgroud)

objective-c instruments objective-c-blocks automatic-ref-counting

15
推荐指数
1
解决办法
3724
查看次数