【问题标题】:Leaks when using RaptureXML with XPath将 RaptureXML 与 XPath 一起使用时泄漏
【发布时间】:2012-05-07 18:19:03
【问题描述】:

我正在使用 RaptureXML 解析一个 XML 文件,该文件描述了不同的过滤器(具有相当复杂的结构),然后我将其创建为 Obj-C 对象。一切正常!

但是,Instruments 在 libxml2.2.dylib 中检测到多个泄漏(请参见屏幕截图),我无法在网上找到任何可以帮助我解决此问题的内容。

这是 Leaks Instrument 屏幕截图的链接(我还不能发布到 sof...)

http://imageshack.us/photo/my-images/850/bildschirmfoto20120507ud.png/

这是我用来解析 xml 文件的代码:

RXMLElement *rootXML = [RXMLElement elementFromXMLData:xmlDataFile];

FilterLogic_Management *filterManager = [[FilterLogic_Management alloc] init];

NSString *queryPath = [NSString stringWithFormat:@"//%@[@id=%i]/filterSettings/fqFilter", FilterTypeAsString, FilterNum];

//WHAT AM I DOING? Consider two filter types: Distance and Price. Each filter type consists of different thresholds (e.g., <8 $;  8 - 15 $; > 15 $). All of these values are in an XML file which I need to parse and translate into my "real" filters that I use in the App.

//Step 1: Iterate over all FilterTypes to find the entry in the XML file that describes the currently selected FilterType and its FilterNum

[rootXML queryPath usingBlock:^(RXMLElement *filterElement) {

    NSMutableArray *currentThresholds = [[NSMutableArray alloc] init];

    float currentWeight = [filterElement attribute:@"weightFactor"].floatValue; //e.g., 1.0           
    NSString *currentMarkerUnit = [filterElement attribute:@"markerUnit"]; //e.g., $ or €
    NSString *currentFilterType = [filterElement attribute:@"groupType"]; //e.g., "Distance" or "Price"



    //Step 2: Iterate over all Filters for current FilterType <- a FilterType consists of an array of Filters...


    [filterElement iterate:@"filter" usingBlock: ^(RXMLElement *filter) {
        NSString *filterType = [filter attribute:@"filterType"];

        if(filterType != LogicalConjunction){
            //Step 3-a: Create threshold with more than one threshold

            float threshold = [filter attribute:@"threshold"].floatValue;

            FilterLogic_FilterThreshold *newThreshold = [FilterLogic_FilterThreshold FilterThresholdMakeWithOneThreshold:threshold FilterWrapperType:filterTypeAsEnum MarkerUnit:currentMarkerUnit IsInitiallyActive:isInitiallyActive];

            [currentThresholds addObject:newThreshold];
        }else{
            //Step 3-b: Create threshold with multiple thresholds
            NSLog(@"Creating filter with multiple thresholds");

            FilterLogic_FilterThreshold *logicalThreshold = [FilterLogic_FilterThreshold FilterThresholdMakeLogicalThreshold:filterTypeAsEnum MarkerUnit:currentMarkerUnit IsInitiallyActive:isInitiallyActive];

            NSMutableArray *subFilterThresholds = [[NSMutableArray alloc] init];
            [filter iterate:@"filter" usingBlock: ^(RXMLElement *subFilter) {
                //Step-3b-x Iterate over sub-thresholds
                float threshold = [subFilter attribute:@"threshold"].floatValue;

                FilterLogic_FilterThreshold *subFilterThreshold = [FilterLogic_FilterThreshold FilterThresholdMakeWithOneThreshold:threshold];


                [subFilterThresholds addObject:subFilterThreshold];

            }];
            if([subFilterThresholds count]>1)
            {
                FilterLogic_FilterThreshold *newThreshold = [FilterLogic_FilterThreshold FilterThresholdMakeFromLowerFilterThreshold:[subFilterThresholds objectAtIndex:0] UpperFilterThreshold:[subFilterThresholds objectAtIndex:1] LogicalFilterThreshold:logicalThreshold];

                [currentThresholds addObject:newThreshold];
            }

        }
    }];    

    FilterLogic_Filter *newFilter = [[FilterLogic_Filter alloc] initFilterWithType:FilterTypeAsEnum ArrayOfFilterLogic_FilterThresholds:currentThresholds Weight:currentWeight InitiallyActive:YES];



    [filterManager registerFilterWrapper:newFilter];

}];

//thought that these commands might help... it seems they don't. Probably misusing them!
xmlCleanupMemory(); 
xmlCleanupParser();

//if([filterManager countOfFilters]>0){
    NSLog(@"Filter parsing done!");
    return filterManager;

非常感谢您的任何帮助/建议!

【问题讨论】:

    标签: ios xml xcode parsing memory-leaks


    【解决方案1】:

    尝试将整个 queryPath usingBlock 位放入 @autoreleasepool {...} 中。只是一个想法。

    【讨论】:

    • 谢谢你的想法,rnystrom。但是,泄漏仍然发生:/
    • 尝试运行 Leaks Instrument,将 Leaked Blocks 设置为 Call Tree 并选择 Invert Call Tree 和 Hide System Libraries 并再次检查泄漏。这可能有助于查明发生泄漏的位置。
    • 太棒了! Thx,反转调用树真的很有帮助!它在两点泄漏:-[RXMLElement childrenWithRootXPath:] -> 21 KB,有 111 次泄漏 -[RXMLElement attribute:] -> 4 KB,有 265 次泄漏 所以第一个不经常泄漏,但是当它发生时,它的“重”
    • 我把两个泄露的截图上传到了imageshack.us:这是RXMLElement属性的泄露link这是RXMLElement的泄露childrenWithRootXPathlink
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 2016-05-09
    • 2018-04-29
    相关资源
    最近更新 更多