iphone - 内存泄漏导致应用崩溃

标签 iphone xcode memory-management crash

我的应用程序在设备上而不是模拟器上的内存崩溃较低,我使用了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/

相关文章:

ios - 在 iOS 中将字符串拆分为子字符串

ios - 导出通用分发框架

iphone - 关闭从 UIWebView 打开的 UIActionSheet

objective-c - 为什么 Xcode 使用 NSStringFromClass([AppDelegate class]) 而不是仅仅使用 @"AppDelegate"或 nil

ios - 了解临时对象的使用

c++ - Vulkan/VMA 更改缓冲区大小,类似于 `realloc`

android - 确保审计表不影响应用程序使用的 RAM

iphone - UITableView 单元格内的 UITextField

iphone - 检索在 sqlite 数据库中插入的所有行,并在包含标签的 TableView 单元格中显示为具有不同部分的 subview

objective-c - iOS/Objective-C 上的谷歌 Protocol Buffer