我在iOS5.0上绘制了一些带有 core-plot 的图,并且由 CA :: Transaction :: create()frame 和 QuartzCore导致了内存泄漏库发生了。一旦我调用了绘图功能,就会增加4.00KB。有人遇到过这个问题吗?我是核心情节的新手......
- (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];
}