KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
So I'm using recursive blocks. I understand that for a block to be recursive it needs to be preceded by the __block keyword, and it must be copied so it can be put on the heap. However, when I do this, it is showing up as a leak in Instruments. Does anybody know why or how I can get around it? Please note in the code below I've got references to a lot of other blocks, but none of them are recursive. __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){ if ([function isEqualToString:@"AVG("]) return Average(list); if ([function isEqualToString:@"MIN("]) return Minimum(list); if ([function isEqualToString:@"MAX("]) return Maximum(list); if ([function isEqualToString:@"SQRT("]) return SquareRoot(list); if ([function isEqualToString:@"ABS("]) return EvaluateStack(list).absoluteValue; return EvaluateStack(list); } else break; } } return EvaluateStack(list); } copy]; NSDecimalNumber *number = ProcessElementStack([formula copy], nil); UPDATE So in my own research I've discovered that
Tags (comma-separated)
Save Edits
Cancel