2010-02-06 97 views
0

我再次发布这个问题,但这次我包括完整的代码。这是非常漫长的,但这里什么也没有。我不知道在哪里发布路径?我相信这是我的最后一次泄漏,希望。我在哪里可以发布CGMutablePath?

-(void)MoveObject:(int)Tag 
    { 
     representationX = gameViewObj.spaceshipImageView.center.x; 
     representationY = gameViewObj.spaceshipImageView.center.y; 

     CALayer *spaceshipLayer = gameViewObj.spaceshipImageView.layer; 
     shipAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
     CGMutablePathRef thePath = CGPathCreateMutable(); 
     CGPathMoveToPoint(thePath, NULL, representationX, representationY); 
     statusFire = YES; 
     BOOL parsedF = NO; 

     if(Tag==LeftButtonTag) 
     { 
      gameViewObj.spaceshipImageView.transform = CGAffineTransformMakeRotation(M_PI + M_PI_2); 

      previousButtonTag = LeftButtonTag; 
      representationX--; 
      CGPathAddLineToPoint(thePath, NULL,representationX, representationY); 

      parsedF = YES; 
     } 
     else if(Tag==UpButtonTag) 
     { 
      gameViewObj.spaceshipImageView.transform = CGAffineTransformMakeRotation(0); 

      previousButtonTag = UpButtonTag; 
      representationY--; 

      CGPathAddLineToPoint(thePath, NULL,representationX, representationY); 

      parsedF = YES; 
     } 
     else if(Tag==RightButtonTag) 
     { 
      gameViewObj.spaceshipImageView.transform = CGAffineTransformMakeRotation(M_PI/2); 

      previousButtonTag = RightButtonTag; 
      representationX++; 

      CGPathAddLineToPoint(thePath, NULL,representationX, representationY); 

      parsedF = YES; 
     } 
     else if(Tag==DownButtonTag) 
     { 
      gameViewObj.spaceshipImageView.transform = CGAffineTransformMakeRotation(M_PI); 

      previousButtonTag = DownButtonTag; 
      representationY++; 

      CGPathAddLineToPoint(thePath, NULL,representationX, representationY); 

      parsedF = YES; 
     } 

     if(parsedF){ 

      shipAnimation.path = thePath; 
      shipAnimation.delegate = self; 
      shipAnimation.duration = 0.003; 
      [spaceshipLayer addAnimation:shipAnimation forKey:@"position"]; 

      //To kill spaceship when moved backwards. 
      if(playField[representationX][representationY]==3){ 

       [self doDie]; 
      } 

      if(playField[representationX][representationY] == 2){ 

       if(onSecretLine){ 

        [gameViewObj.spaceshipImageView setCenter:CGPointMake(representationX, representationY)]; 

        oldPositionX = representationX; 
        oldPositionY = representationY; 
       } 
      } 

      // case: breaking out 
      if (playField[representationX][representationY]==0){ 
       if (onSecretLine){ 
        if (statusFire) 
        { 
         availableOffline = YES; 

         oldPositionX=gameViewObj.spaceshipImageView.center.x; 
         oldPositionY=gameViewObj.spaceshipImageView.center.y; 

         [gameViewObj DrawLine]; 

         onSecretLine = NO; 
         availableOffline = NO; 
        } 
       } 
      } 

      if (playField[representationX][representationY]==0) 
       if (!onSecretLine) 
       { 
        BOOL doIt=true; 

        // ------------------------------ 
        // prevent contact own line 
        // ------------------------------ 
        // left 
        if (Tag==LeftButtonTag) { 
         if (playField[representationX-1][representationY]==3) { 

          [self doDie]; 
          doIt=false; 
         } 
        } 
        // right 
        if (Tag==RightButtonTag) { 
         if (playField[representationX+1][representationY]==3) { 

          [self doDie]; 
          doIt=false; 
         } 
        } 
        // up 
        if (Tag==UpButtonTag) { 
         if (playField[representationX][representationY-1]==3) { 

          [self doDie]; 
          doIt=false; 
         } 
        } 
        // down 
        if (Tag==DownButtonTag) { 
         if (playField[representationX][representationY+1]==3) { 

          [self doDie]; 
          doIt=false; 
         } 
        } 

        // special things ... 
        if (doIt) 
        { 
         playField[representationX][representationY]=3; 

         [gameViewObj DrawLine]; 
        } 

       } 

      // case: back to the secure line 
      if (playField[representationX][representationY]==2) 
       if (!onSecretLine) 
       {    
        [gameViewObj.spaceshipImageView setCenter:CGPointMake(representationX, representationY)]; 
        availableOffline = NO; 
        onSecretLine = YES; 
        [[NSNotificationCenter defaultCenter] postNotificationName:@"FindBirdCenter" object:nil]; 

        for (int i=0; i<[gameViewObj.birdImageViewArray count]; i++) { 
         UIImageView* ImgBird=[gameViewObj.birdImageViewArray objectAtIndex:i]; 
         int px=ImgBird.center.x; 
         int py=ImgBird.center.y; 
         // cristall point 
         playField[px][py]=5; 
        } 

        [self fillPlaygroundExtended]; 

        //Elan function for filling area enclosed 
        [self fillAreaEnclosed:gameViewObj._myContext]; 

        // invert .. 
        [self invertPlayground]; 

        // turn the 3 into -> 20+ 
        [self generateNewSecureLine]; 

       } 

      if(Tag == UpButtonTag){ 

       [self moveShipUp]; 
      } 

      else if(Tag == RightButtonTag){ 

       [self moveShipRight]; 
      } 

      else if(Tag == DownButtonTag){ 

       [self moveShipDown]; 
      } 

      else if(Tag == LeftButtonTag){ 

       [self moveShipLeft]; 

      } 
      if(doScore == YES){ 
       [self calculateScore]; 
       doScore = NO; 
      } 
      [gameViewObj setNeedsDisplay]; 
     } 
    } 
+0

我已经添加了这个代码到你原来的问题:http://stackoverflow.com/questions/2209559/where-am -i-leaking-cgmutablepathref-in-this-code,所以这应该作为重复来关闭。 – 2010-02-06 16:05:27

回答

0

其实,如果你看看CAAnimation.h CAKeyframeAnimation接口,它宣称其路径财产一样,

@property CGPathRef path; 

由于默认的是“分配”属性,你不应该释放如果将该变量分配给shipAnimation.path。只有当您不将其分配给shipAnimation.path时,才应该释放它。

所以,我要说你添加一个其他你下面的循环

if (parsedF) { 
    ... 
} else { 
    CFPathRelease(thePath); 
} 
+0

我一定会尝试一下,谢谢! – NextRev 2010-02-06 07:18:27