Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

build and analyze not working in my project

In my iPhone Project when i select build and analyze (shift + mac + A ) it will give me all potential memory leak in my project... but in my current project it is not working... when i intentionally put a memory leak and select build and analyze... it doesn't give me any potential memory leak as analyzer result

if i write

NSMutableArray *tempArray = [[NSMutableArray alloc] initWithCapacity:6];
NSMutableArray *tempArrayfinal = [[NSMutableArray alloc] initWithCapacity:12];

and doesn't release it... it is not giving me any potential leak but if i write

NSString *leakyString = [[NSString alloc] initWithString:@"Leaky String "];
NSLog(@"%@",leakyString);

here it gives me potential leak as analyzer result...why it is not giving potential leak in NSMutableArray and why it gives potential leak in NSString ?... how can i rely on Build and analyze for memory leak...

I've run the app with Leak tool and it is showing me leak in tempArray and tempArrayfinal

Here is my function

- (void)viewDidLoad 
{
    [super viewDidLoad];

    maxOnSnaxAppDelegate *delegate = (maxOnSnaxAppDelegate *)[[UIApplication sharedApplication] delegate];
    lblMessage.tag = MESSAGE_LABEL;
    lblGuess.tag = GUESS_LABEL;
    lblScore.tag = SCORE_LABEL;
    self.gameCompleteView.tag = FINAL_SCORE_VIEW;
    lblFinalScore.tag = FINAL_SCORE_LABEL;

    lblGuess.text = @"";
    lblMessage.text = @"";
    lblScore.text = @"";

    int row = 0;
    int column = 0;

    maxImagrArray = [[NSMutableArray alloc] init];

    for(UIView *subview in [self.view subviews]) {

        if([subview isKindOfClass:[CustomImageView class]])
        {
            [subview removeFromSuperview];
        }
    }

    for(int i = 0 ; i < 12 ; i++)
    {
        if(i%3 == 0 && i != 0)
        {
            row++;
            column = -1;
        }
        if(i != 0 )
        {
            column++;
            //row = 0;
        }
        CustomImageView *tempImageView = [[CustomImageView alloc] initWithImage:[UIImage imageNamed:@"max-img.png"]];


        tempImageView.frame = CGRectMake((column*tempImageView.frame.size.width) + 45, (row*tempImageView.frame.size.height)+ 60, tempImageView.frame.size.width, tempImageView.frame.size.height);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextClearRect(context, tempImageView.bounds);
        [self.view addSubview:tempImageView];
        tempImageView.tag = i+1;
        tempImageView.userInteractionEnabled = YES;
        [maxImagrArray addObject:tempImageView];

        [tempImageView setIndex:i]; 

        [tempImageView release];
    }

    NSMutableArray *tempArray = [[NSMutableArray alloc] initWithCapacity:6];
    NSMutableArray *tempArrayfinal = [[NSMutableArray alloc] initWithCapacity:12];
    for(int i = 0 ; i < 12 ; i++)
    {
        if(i < 6)
        {
            int temp = (arc4random() % 10) + 1;
            NSString *tempStr = [[NSString alloc] initWithFormat:@"%d",temp];
            [tempArray insertObject:tempStr atIndex:i];
            [tempArrayfinal insertObject:tempStr atIndex:i];
            [tempStr release];

        }
        else
        {
            int temp = (arc4random() % [tempArray count]);
            [tempArrayfinal insertObject: (NSString *)[tempArray objectAtIndex:temp] atIndex:i];
            //int  index = [(NSString *)[tempArray objectAtIndex:temp] intValue];
            [tempArray removeObjectAtIndex:temp];

        }
        CustomImageView *tmpCustom = [maxImagrArray objectAtIndex:i];
        tmpCustom.frontImageIndex = [(NSString *)[tempArrayfinal objectAtIndex:i] intValue];
        NSLog(@"%d",tmpCustom.frontImageIndex);
    }
    [maxImagrArray release];
    delegate.time = 60.0;

    timer = nil; 

    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
    delegate.view = self.view;

    //[tempArray release];
    //[tempArrayfinal release];//these 2 lines are deliberately commented to see
//...it is not showing any  potential memory leak though....
    delegate.viewController = self;

}

please help...

like image 282
Mihir Mehta Avatar asked Nov 30 '25 04:11

Mihir Mehta


1 Answers

[tempArray insertObject:tempStr atIndex:i];
 [tempArrayfinal insertObject:tempStr atIndex:i];

are the culprits... when i uncomment these 2 lines.. it stops giving me the warning... i don't know why...

like image 58
Mihir Mehta Avatar answered Dec 02 '25 21:12

Mihir Mehta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!