0

I have integrated CorePlot bar graph library in my project but my graph is crashing , due to memory leak , I have enabled NSZombieEnabled aswell but it is crashing as my crash log as below.

* thread #1: tid = 0x38f7f, 0x0529a2e0 libsystem_kernel.dylib`vm_allocate + 18, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0xbf78fff8)
    frame #0: 0x0529a2e0 libsystem_kernel.dylib`vm_allocate + 18
    frame #1: 0x00a7e57f libgmalloc.dylib`GMmalloc_zone_malloc_internal + 731
    frame #2: 0x00a7d3fc libgmalloc.dylib`GMmalloc_zone_malloc + 89
    frame #3: 0x00a7d26d libgmalloc.dylib`GMmalloc_zone_calloc + 100
    frame #4: 0x00a7cee4 libgmalloc.dylib`GMcalloc + 58
    frame #5: 0x042e3cc1 libobjc.A.dylib`class_createInstance + 68
    frame #6: 0x0460dbe1 CoreFoundation`__CFAllocateObject2 + 33
    frame #7: 0x0460dd08 CoreFoundation`+[__NSArrayI __new:::] + 40
    frame #8: 0x0460de4c CoreFoundation`-[__NSPlaceholderArray initWithObjects:count:] + 204
    frame #9: 0x01d855b3 QuartzCore`-[CALayerArray copyWithZone:] + 80
    frame #10: 0x042edb45 libobjc.A.dylib`-[NSObject copy] + 41
    frame #11: 0x02b16da1 UIKit`-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 200
    frame #12: 0x02b16fe2 UIKit`__85-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]_block_invoke + 162
    frame #13: 0x02b16eb9 UIKit`-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 480
    frame #14: 0x02b16fe2 UIKit`__85-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]_block_invoke + 162
    frame #15: 0x02b16eb9 UIKit`-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 480
    frame #16: 0x02b16fe2 UIKit`__85-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]_block_invoke + 162
    frame #17: 0x02b16eb9 UIKit`-[UIView(Hierarchy) 

I am also enclosing my GraphView code aswell and remove dealloc from code aswell but couldnt figure out the reason for crash

- (void)generateData:(NSArray *)customerArr  withVisitCounts:(NSArray *)visitCountsArr
{
    NSMutableDictionary *dataTemp = [[NSMutableDictionary alloc] init];

    //Array containing all the dates that will be displayed on the X axis
    dates = [NSArray arrayWithObjects:@"TestData", @"TestData", @"TestData",
             @"TestData", @"TestData", nil];

    //Dictionary containing the name of the two sets and their associated color
    //used for the demo
    sets = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor blueColor], @"Plot 1", nil];

    //Generate random data for each set of data that will be displayed for each day
    //Numbers between 1 and 10
    for (NSString *date in dates) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        for (NSString *set in sets) {
            NSNumber *num = [NSNumber numberWithInt:arc4random_uniform(10)+1];
            [dict setObject:num forKey:set];
        }
        [dataTemp setObject:dict forKey:date];
    }

    self.data =  [NSDictionary dictionaryWithDictionary:[dataTemp copy]];
    [dataTemp release];

    NSLog(@"%@", data);
}

GraphView files also enclosed

My Project is ARC with new xcode 6.1.1 but I am using -fno-objc-arc in Compiled Sources of GraphView, and I have download library from Core Plot Bar Github

user366584
  • 1,016
  • 1
  • 16
  • 34

1 Answers1

0

Enable ARC in the GraphView class. It's an easy conversion and it will fix a couple of obvious memory management errors (and maybe some other not-so-obvious ones). The line [plot.dataSource retain]; is equivalent to [self retain];, so the view will never be deallocated. Also, the [dataTemp copy] in -generateData: withVisitCounts: is never released.

Eric Skroch
  • 27,381
  • 3
  • 29
  • 36
  • I tried by enabling ARC in GraphView class and commented out [plot.dataSource retain]; and also removed dataTemp copy but no luck :( – user366584 Jan 31 '15 at 08:44