内存泄漏在main.m而在仪器分析?

在我的应用程序之一,我得到UIKit,Uifoundation和QuartzCore内存泄漏。 当我去呼叫树显示在main.m泄漏。 我真的没有任何线索,为什么会发生这种情况。 你可以看到下面的内存泄漏的屏幕截图。 在这里输入图像说明

在调用树

在这里输入图像说明

如何解决这个泄漏?

内存泄漏代码

 - (void) showCustomPrices { int priceValue = 0; NSArray* priceSplitValue = [btnpriceButton.titleLabel.text componentsSeparatedByString: @"."]; NSString* priceFinal = [priceSplitValue objectAtIndex:0]; for(int i=0;i<[priceArray count];i++) { if([[priceArray objectAtIndex:i] isEqualToString:priceFinal]){ priceValue = i; } } //Assign the cocktail to picker view priceActionsheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];//as we want to display a subview we won't be using the default buttons but rather we're need to create a toolbar to display the buttons on [priceActionsheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; CGRect pickerFrame = CGRectMake(0, 40, 0, 0); pricePickerview = [[UIPickerView alloc] initWithFrame:pickerFrame]; pricePickerview.showsSelectionIndicator = YES; pricePickerview.dataSource = self; pricePickerview.delegate = self; [priceActionsheet addSubview:pricePickerview]; //[pickerView release]; priceToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 485, 44)]; priceToolbar.barStyle = UIBarStyleBlackTranslucent; [priceToolbar sizeToFit]; NSMutableArray *barItems = [[NSMutableArray alloc] init]; UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; [barItems addObject:flexSpace]; UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)]; [barItems addObject:doneBtn]; UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)]; [barItems addObject:cancelBtn]; [pricePickerview selectRow:priceValue inComponent:0 animated:YES];//Memory leaks shows 100% here [priceToolbar setItems:barItems animated:YES]; [priceActionsheet addSubview:priceToolbar]; [priceActionsheet addSubview:pricePickerview]; [priceActionsheet showInView:self.view]; [priceActionsheet setBounds:CGRectMake(0, 0, 485, 320)]; 

}

任何帮助深表感谢。

如果你的项目是非ARC,可能是因为你离开了[super dealloc]; 在某个地方inheritance基础课程。 我有一个与NSObject的子类相同的问题。 我忘了写[super dealloc]; 并得到了一些类似的泄漏。

最后我解决了我的问题,通过将方法showCustomePrices的select器视图allocation/initialisation部分移到viewwillAppear 。 哪个工作真棒没有任何内存泄漏。

什么是之前发生的是每当我点击buttonpopuppickerview内存分配。 这就是为什么发生内存泄漏。

现在进入viewwillAppear ,只需在视图加载的时候第一次分配。 然后Picker View被访问,没有任何内存分配。 所以内存泄漏被删除。

 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; 

在你的main.m中试试这个

 int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, @"yourAppName", nil); [pool release]; return retVal; }