CoreAnimation:我的iPad应用程序无法分配1971232字节?

时间:2012-10-12 12:29:03

标签: memory-leaks core-animation core-plot ipad-2

我正在使用核心绘图框架工作,我在一段时间后刷新视图我得到了错误 “CoreAnimation:未能分配1971232字节”。 这里附有我用于绘图聊天的代码

- (void)ipadDraw
{
    CPTGradient *overlayGradient = [[[CPTGradient alloc] init] autorelease];
    overlayGradient.gradientType = CPTGradientTypeRadial;
    overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.0] atPosition:0.0];
    overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.5] atPosition:0.9];
    overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.8] atPosition:1.0];
    CGRect rect=self.view.bounds;


    if(currentOrientation   == UIInterfaceOrientationPortrait || currentOrientation== UIInterfaceOrientationPortraitUpsideDown)
    {

        NSLog(@"%@",NSStringFromCGRect(rect));
        rect.size.width = rect.size.width;
        rect.origin.x=0;
        rect.origin.y-=120;
    }
    else 
    {
        NSLog(@"%@",NSStringFromCGRect(rect));

        rect.origin.x=60;
        rect.origin.y+=25;
        rect.size.width=600;
        rect.size.height=700;
    }




    defaultLayerHostingView = [(CPTGraphHostingView *)[CPTGraphHostingView alloc] initWithFrame:rect];
      defaultLayerHostingView.userInteractionEnabled=YES;
    defaultLayerHostingView.exclusiveTouch=YES;
    defaultLayerHostingView.multipleTouchEnabled=YES;
    defaultLayerHostingView.backgroundColor= [UIColor clearColor];
    //defaultLayerHostingView.delegate=self;

    [myScrollView addSubview:defaultLayerHostingView];
    myScrollView.delegate=self;


    CGRect bounds  = defaultLayerHostingView.bounds;
    graph  = [[CPTXYGraph alloc] initWithFrame:[defaultLayerHostingView bounds]];

    defaultLayerHostingView.hostedGraph = graph; 

    CPTMutableTextStyle *textStyle  = [CPTMutableTextStyle textStyle];//
    textStyle.color = [CPTColor grayColor];
    textStyle.fontName = @"Helvetica-Bold";
    textStyle.fontSize = bounds.size.height / 20.0f;
    graph.titleTextStyle = textStyle;
    graph.titleDisplacement = CGPointMake(0.0f, bounds.size.height / 18.0f);
    graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
    graph.plotAreaFrame.masksToBorder = NO;

    // Graph padding
    CGFloat boundsPadding = bounds.size.width / 20.0f;
    NSLog(@"the bounds padding is %f",boundsPadding);
    graph.paddingLeft = boundsPadding;
    graph.paddingTop = graph.titleDisplacement.y * 2;
    graph.paddingRight = 32;
    graph.paddingBottom = boundsPadding;
    graph.axisSet = nil;

    // Add pie chart

     CPTPieChart *piePlot = [[CPTPieChart alloc] init];

    piePlot.dataSource = self;
    piePlot.title=@"First";


    piePlot.pieRadius=200;
    piePlot.startAngle = M_PI_4;
    piePlot.sliceDirection = CPTPieDirectionCounterClockwise;
    piePlot.overlayFill = [CPTFill fillWithGradient:overlayGradient];
    piePlot.delegate = self;
    [graph addPlot:piePlot];

    [piePlot release];

    CPTLegend *theLegend = [CPTLegend legendWithGraph:graph];
    theLegend.numberOfColumns = 2;
    theLegend.fill = [CPTFill fillWithColor:(CPTColor *)[UIColor clearColor]];
    theLegend.cornerRadius = 5.0;
    theLegend.swatchSize=CGSizeMake(25, 25);
    theLegend.textStyle=textStyle1;
    graph.legend = theLegend;
    graph.legendAnchor =CPTRectAnchorCenter;


    graph.legendDisplacement=CGPointMake(-10, -275);

    UIButton *ProceedButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [ProceedButton setImage:[UIImage imageNamed:@"details_button_land.png"] forState:UIControlStateNormal];
    [ProceedButton setUserInteractionEnabled:YES];

    [myScrollView  addSubview:claimsProceedButton];
    ProceedButton.tag=0;
    if(currentOrientation   == UIInterfaceOrientationPortrait || currentOrientation== UIInterfaceOrientationPortraitUpsideDown)
    {


        [ProceedButton setFrame:CGRectMake((myScrollView.frame.size.width-300)/2, 720, 300.00 , 51.00)];
    }
    else{
        [ProceedButton setFrame:CGRectMake((myScrollView.frame.size.width-300)/2, 690, 300.00 , 51.00)];
    }


    rect=self.view.bounds;
    [ProceedButton addTarget:self action:@selector(ProceedDetail:) forControlEvents:UIControlEventTouchUpInside];
    UILabel *viewDetails = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300.00, 51.00)];
    [ProceedButton addSubview:viewDetails];
    [viewDetails setText:@"View Chart Data"];
    [viewDetails setFont:[UIFont boldSystemFontOfSize:13]];
    [viewDetails setBackgroundColor:[UIColor clearColor]];
    [viewDetails setTextAlignment:UITextAlignmentCenter];

    NSLog(@"%@",NSStringFromCGRect(rect));

    rect=self.view.bounds;

    defaultLayerHostingView=nil;

}

2 个答案:

答案 0 :(得分:0)

初始化对象时可以自动释放

答案 1 :(得分:0)

您可以将现有代码替换为此

    - (void)ipadDraw

{

CPTGradient *overlayGradient = [[[CPTGradient alloc] init] autorelease];
overlayGradient.gradientType = CPTGradientTypeRadial;
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.0] atPosition:0.0];
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor]
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.5] atPosition:0.9];
enter code here   overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.8] atPosition:1.0];

CGRect rect=self.view.bounds;if(currentOrientation==UIInterfaceOrientationPortrait || currentOrientation== UIInterfaceOrientationPortraitUpsideDown)
  { NSLog(@"%@",NSStringFromCGRect(rect));



rect.size.width = rect.size.width;
rect.origin.x=0;
rect.origin.y-=120;
}

else { 
 NSLog(@"%@",NSStringFromCGRect(rect)); 
rect.origin.x=60;
rect.origin.y+=25;
rect.size.width=600;
rect.size.height=700;
}

defaultLayerHostingView = [[(CPTGraphHostingView *)[CPTGraphHostingView alloc] initWithFrame:rect]autorelease];
defaultLayerHostingView.userInteractionEnabled=YES;
defaultLayerHostingView.exclusiveTouch=YES;
defaultLayerHostingView.multipleTouchEnabled=YES;
defaultLayerHostingView.backgroundColor= [UIColor clearColor];
[myScrollView addSubview:defaultLayerHostingView];
myScrollView.delegate=self;
CGRect bounds  = defaultLayerHostingView.bounds;
graph  = [[[CPTXYGraph alloc] initWithFrame:[defaultLayerHostingView bounds]]autorlease];
defaultLayerHostingView.hostedGraph = graph; 

CPTMutableTextStyle *textStyle  = [CPTMutableTextStyle textStyle];//
textStyle.color = [CPTColor grayColor];
textStyle.fontName = @"Helvetica-Bold";
textStyle.fontSize = bounds.size.height / 20.0f;
graph.titleTextStyle = textStyle;
graph.titleDisplacement = CGPointMake(0.0f, bounds.size.height / 18.0f);
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.plotAreaFrame.masksToBorder = NO;

// Graph padding
CGFloat boundsPadding = bounds.size.width / 20.0f;
NSLog(@"the bounds padding is %f",boundsPadding);
graph.paddingLeft = boundsPadding;
graph.paddingTop = graph.titleDisplacement.y * 2;
graph.paddingRight = 32;
graph.paddingBottom = boundsPadding;
graph.axisSet = nil;

// Add pie chart

 CPTPieChart *piePlot = [[[CPTPieChart alloc] init]autorelease];

piePlot.dataSource = self;
piePlot.title=@"First";


piePlot.pieRadius=200;
piePlot.startAngle = M_PI_4;
piePlot.sliceDirection = CPTPieDirectionCounterClockwise;
piePlot.overlayFill = [CPTFill fillWithGradient:overlayGradient];
piePlot.delegate = self;
[graph addPlot:piePlot];

[piePlot release];

CPTLegend *theLegend = [CPTLegend legendWithGraph:graph]autorlease];
theLegend.numberOfColumns = 2;
theLegend.fill = [CPTFill fillWithColor:(CPTColor *)[UIColor clearColor]];
theLegend.cornerRadius = 5.0;
theLegend.swatchSize=CGSizeMake(25, 25);
theLegend.textStyle=textStyle1;
graph.legend = theLegend;
graph.legendAnchor =CPTRectAnchorCenter;


graph.legendDisplacement=CGPointMake(-10, -275);

UIButton *ProceedButton = [[UIButton buttonWithType:UIButtonTypeCustom];
[ProceedButton setImage:[UIImage imageNamed:@"details_button_land.png"] forState:UIControlStateNormal]autorelease];
[ProceedButton setUserInteractionEnabled:YES];

[myScrollView  addSubview:claimsProceedButton];
ProceedButton.tag=0;
if(currentOrientation   == UIInterfaceOrientationPortrait || currentOrientation== UIInterfaceOrientationPortraitUpsideDown)
{


    [ProceedButton setFrame:CGRectMake((myScrollView.frame.size.width-300)/2, 720, 300.00 , 51.00)];
}
else{
    [ProceedButton setFrame:CGRectMake((myScrollView.frame.size.width-300)/2, 690, 300.00 , 51.00)];
}


rect=self.view.bounds;
[ProceedButton addTarget:self action:@selector(ProceedDetail:) forControlEvents:UIControlEventTouchUpInside];
UILabel *viewDetails = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300.00, 51.00)];
[ProceedButton addSubview:viewDetails];
[viewDetails setText:@"View Chart Data"];
[viewDetails setFont:[UIFont boldSystemFontOfSize:13]];
[viewDetails setBackgroundColor:[UIColor clearColor]];
[viewDetails setTextAlignment:UITextAlignmentCenter];

NSLog(@"%@",NSStringFromCGRect(rect));

rect=self.view.bounds;

defaultLayerHostingView=nil;

}