gpt4 book ai didi

iphone - 在 Instruments 中进行分析时 main.m 中的内存泄漏?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:23:31 25 4
gpt4 key购买 nike

在我的其中一个应用程序中,我在 UIKit、UIFoundation 和 QuartzCore 中发生内存泄漏。当我去寻找调用树时,它在 main.m 中显示泄漏。我真的不知道为什么会这样。您可以在下面看到内存泄漏的屏幕截图。 enter image description here

在调用树中

enter image description here

如何解决这个漏洞?

内存泄漏代码

- (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]; 留在了某个地方子类化基础类。我对 NSObject 的子类也有同样的问题。我忘了写 [super dealloc]; 并且得到了一些类似的泄漏。

关于iphone - 在 Instruments 中进行分析时 main.m 中的内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13644655/

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