我的应用程序在设备上而不是模拟器上的内存崩溃较低,我使用了Instruments,我认为问题出在以下部分
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"gembtnblu.png"] forState:UIControlStateNormal];<br>
button.frame = CGRectMake(0, 0, TOOLBAR_BUTTON_WIDTH , TOOLBAR_BUTTON_HEIGHT);<br>
[button setTitle:[NSString stringWithFormat:@"%c",choice] forState:UIControlStateNormal];<br>
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(ChoiceButtonTouched:) forControlEvents:UIControlEventTouchUpInside];
[button setTag:choice];
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
//Add button to the array
[tempItems addObject:customBarItem];
if (isReviewing == TRUE) {
customBarItem.customView.userInteractionEnabled=FALSE;
}
//release buttons
[customBarItem release];
numberOfChoices++;
但我无法发现问题。请帮忙,我已经被困在这里好几天了
继承人一些代码
NSArray *items=[[NSArray alloc] initWithArray:(NSArray *)tempItems];
[tempItems release];
//add array of buttons to toolbar
[toolbar setItems:items animated:YES];
[self.view addSubview:toolbar];
静态分析器说'items'数组可能存在泄漏,但是如果我发布了release语句,则应用程序崩溃
最佳答案
在将工具栏添加为 subview 后是否释放了工具栏?如果您没有这样做,并且没有在dealloc中释放工具栏,则可能会导致泄漏。
关于iphone - 内存泄漏导致应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5195052/