Take the 2-minute tour ×

I am using RaptureXML to parse an XML file which describes different filters (with a rather complex structure), which I then create as Obj-C objects. All works fine!

However, Instruments detects several leaks in libxml2.2.dylib (see screenshot) and I cant find anything online that could help me with this issue.

Here is a link to a screenshot of the Leaks Instrument (I cant post it to sof yet...)


Here is the code I'm using to parse the xml file:

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];
            //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!

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

Thank you VERY MUCH for any help/advice!!

share|improve this question

1 Answer 1

Try putting the entire queryPath usingBlock bit in an @autoreleasepool {...}. Just an idea.

share|improve this answer
thank you for your idea, rnystrom. However, the leaks still occur :/ –  Wirsing May 15 '12 at 13:35
Try running Leaks Instrument setting Leaked Blocks to Call Tree and selecting Invert Call Tree and Hide System Libraries and check the leaks again. That might help pinpoint where the leak is occurring. –  rnystrom May 15 '12 at 15:50
Great! Thx, Invert Call Tree really helps! It leaks at two points: -[RXMLElement childrenWithRootXPath:] -> 21 KB with 111 leaks -[RXMLElement attribute:] -> 4 KB with 265 leaks So the first does not leak often, but when it does, its "heavy" –  Wirsing May 16 '12 at 17:27
I took screenshots of the two leaks and uploaded them to imageshack.us: This is the leak of RXMLElement attribute: link This is the leak of RXMLElement childrenWithRootXPath: link –  Wirsing May 16 '12 at 17:36
Any new ideas on this? –  Wirsing Jun 3 '12 at 12:00

Your Answer


