gpt4 book ai didi

iphone - 构建和分析在我的项目中不起作用

转载 作者:行者123 更新时间:2023-12-03 20:10:55 25 4
gpt4 key购买 nike

在我的iPhone项目中,当我选择构建和分析(shift + mac + A)时,它会给我项目中所有潜在的内存泄漏...但在我当前的项目中它不起作用...当我故意把内存泄漏并选择构建和分析...它不会给我任何潜在的内存泄漏作为分析结果

如果我写

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

并且不释放它......它不会给我任何潜在的泄漏,但如果我写

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

这里它给了我潜在的泄漏作为分析器结果...为什么它没有在 NSMutableArray 中提供潜在的泄漏以及为什么它在 NSString 中提供潜在的泄漏?...我如何依赖构建和分析内存泄漏...

我已经使用 Leak 工具运行了该应用,它显示 tempArraytempArrayfinal 中存在泄漏

这是我的函数

- (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;

}

请帮忙...

最佳答案

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

是罪魁祸首...当我取消注释这两行时..它不再给我警告...我不知道为什么...

关于iphone - 构建和分析在我的项目中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3005948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com