Библиотека QuartzCore и утечка памяти в кадре CA :: Transaction :: create () - PullRequest
1 голос
/ 29 февраля 2012

Я рисую некоторые графики с core-plot на iOS5.0 и утечкой памяти в результате CA :: Transaction :: create () frame и библиотеки QuartzCore произошло. 4.00 КБ будет увеличено, как только я вызову функцию рисования графиков. Кто-нибудь встречался с этой проблемой? Я новичок в основном сюжете ...

- (void)createPiePlot {

// Do any additional setup after loading the view from its nib.
hostingView = [[CPTGraphHostingView alloc] 
                    initWithFrame:CGRectMake(0.0f, 0.0f, 480.0f, 256.0f)];

[self.view addSubview:hostingView];

pieChart = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
[pieChart applyTheme:theme];

hostingView.hostedGraph = pieChart;

pieChart.paddingLeft = 20.0f;
pieChart.paddingTop = 25.0f;
pieChart.paddingRight = 20.0f;
pieChart.paddingBottom = 2.0f;

pieChart.axisSet = nil;

CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.color = [CPTColor whiteColor];

// Add pie chart
piePlotGlobal = [[CPTPieChart alloc] init];
piePlotGlobal.dataSource = self;
piePlotGlobal.pieRadius = 80.0f;
piePlotGlobal.identifier = @"areasPercentage";
piePlotGlobal.startAngle = M_PI_4;
piePlotGlobal.sliceDirection = CPTPieDirectionCounterClockwise;
piePlotGlobal.borderLineStyle = [CPTLineStyle lineStyle];
piePlotGlobal.doubleSided = YES;
piePlotGlobal.delegate = self;

[pieChart addPlot:piePlotGlobal];

// Animate in the new plot
piePlotGlobal.opacity = 0.0f;
CABasicAnimation *fadeInAnimation = [CABasicAnimation    animationWithKeyPath:@"opacity"];
fadeInAnimation.duration = 3.0f;
fadeInAnimation.removedOnCompletion = NO;
fadeInAnimation.fillMode = kCAFillModeForwards;
fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
[piePlotGlobal addAnimation:fadeInAnimation forKey:@"animateOpacity"];

// Release unused memory
[hostingView release], hostingView = nil;
[pieChart release], pieChart = nil;
}


- (void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

if (-1 == selectedViewMode) {
    // Avoid loading twice when fist loaded
    selectedViewMode = 0; 
    return; // Just get out this time
}
switch (selectedViewMode) {

    case 0:
        [self performSelector:@selector(policyButtonPressed:) withObject:nil afterDelay:0.5f];
        break;
    case 1:
        [self performSelector:@selector(insuredButtonPressed:) withObject:nil afterDelay:0.5f];
        break;
    case 2:
        [self performSelector:@selector(premiumButtonPressed:) withObject:nil afterDelay:0.5f];
        break;

    default:
        break;
}
}

#pragma mark - Delegate Methods

- (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {

return [dataForChart count];
}

- (NSNumber *)numberForPlot:(CPTPlot *)plot 
                  field:(NSUInteger)fieldEnum 
            recordIndex:(NSUInteger)index {

if (index >= [dataForChart count]) {

    return nil;
}

if (fieldEnum == CPTPieChartFieldSliceWidth) {

    return [dataForChart objectAtIndex:index];
} else {

    return [NSNumber numberWithInt:index];
}
}

-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot
              recordIndex:(NSUInteger)index {

CPTTextLayer *label = [[CPTTextLayer alloc] 
                       initWithText:[labelArray objectAtIndex:index]];

CPTMutableTextStyle *textStyle = [label.textStyle mutableCopy];
textStyle.color = [CPTColor whiteColor];
textStyle.fontSize = 7.0f;
label.textStyle = textStyle;
[textStyle release];
return [label autorelease];
}

-(CGFloat)radialOffsetForPieChart:(CPTPieChart *)piePlot recordIndex:(NSUInteger)index
{       

if (index < [labelArray count] / 3) {

    return 7.0f;
} else {

    return 3.0f;
}
}

#pragma mark - IBActions

- (IBAction)policyButtonPressed:(id)sender {

[self setImageForToolBarButton:@"policy"];
selectedViewMode = 0;

grabData = [[GrabData alloc] init];

WaitingAndHaveCoffee *waitingView = [[WaitingAndHaveCoffee alloc] init];
[waitingView startWaitingAndEnjoyCoffeeOnTheView];

    // Waiting for downloading data
    [self downloadDataForTypeOf:@"charts" 
                   withRateName:@"PolicyRate" 
      andCorrespondingValueName:@"TotalPolicy"];
    [grabData release], grabData = nil;
    // Waiting for drawing the plots
    [piePlotGlobal reloadData];

[waitingView stopWaiting];
[waitingView release];
waitingView = nil;
}

- (IBAction)insuredButtonPressed:(id)sender {

[self setImageForToolBarButton:@"insurance"];
selectedViewMode = 1;

grabData = [[GrabData alloc] init];

WaitingAndHaveCoffee *waitingView = [[WaitingAndHaveCoffee alloc] init];
[waitingView startWaitingAndEnjoyCoffeeOnTheView];

    // Waiting for downloading data
    [self downloadDataForTypeOf:@"charts" 
                   withRateName:@"InsuranceRate" 
      andCorrespondingValueName:@"TotalInsurance"];
    [grabData release], grabData = nil;
    // Waiting for drawing the plots
    [piePlotGlobal reloadData];

[waitingView stopWaiting];
[waitingView release];
waitingView = nil;
} 

- (IBAction)premiumButtonPressed:(id)sender {

[self setImageForToolBarButton:@"premium"];
selectedViewMode = 2;

grabData = [[GrabData alloc] init];

WaitingAndHaveCoffee *waitingView = [[WaitingAndHaveCoffee alloc] init];
[waitingView startWaitingAndEnjoyCoffeeOnTheView];

    // Waiting for downloading data
    [self downloadDataForTypeOf:@"charts" 
                   withRateName:@"PremiumRate" 
      andCorrespondingValueName:@"TotalPremium"];
    [grabData release], grabData = nil;
    // Waiting for drawing the plots
    [piePlotGlobal reloadData];

[waitingView stopWaiting];
[waitingView release];
waitingView = nil;
}


- (void)dealloc {

[dataForChart release], dataForChart = nil;
[labelArray release], labelArray = nil;

[piePlotGlobal removeFromSuperlayer];
[piePlotGlobal release], piePlotGlobal = nil;

[policyButton release], policyButton = nil;
[insuredButton release], insuredButton = nil;
[premiumButton release], premiumButton = nil;

[super dealloc];
}
...