Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CALayer内存泄漏_Ios_Memory - Fatal编程技术网

Ios CALayer内存泄漏

Ios CALayer内存泄漏,ios,memory,Ios,Memory,希望有人能帮我,因为我已经失去了忍受记忆问题的意愿。 当我按下一个特定的视图控制器时,仪器显示出大约3MB的增长,其中大多数来自属于视图控制器上每个控件的CALayer对象(主要是文本字段和标签)。 当我弹出这个视图控制器时,这些CALayer分配仍保留在内存中,事实上,每次我按下并弹出控制器时,每次都会增加3MB 所以我的问题是如何从内存中删除这些,在释放控制器时是否需要执行某些操作?在我的代码中,对控件层的唯一引用是创建圆角和边框宽度(layer.cornerRadius=10),但即使我将

希望有人能帮我,因为我已经失去了忍受记忆问题的意愿。 当我按下一个特定的视图控制器时,仪器显示出大约3MB的增长,其中大多数来自属于视图控制器上每个控件的CALayer对象(主要是文本字段和标签)。 当我弹出这个视图控制器时,这些CALayer分配仍保留在内存中,事实上,每次我按下并弹出控制器时,每次都会增加3MB

所以我的问题是如何从内存中删除这些,在释放控制器时是否需要执行某些操作?在我的代码中,对控件层的唯一引用是创建圆角和边框宽度(layer.cornerRadius=10),但即使我将其注释掉,仍然会得到增长。 控制器包含一个tableview,其中每个单元格包含3个文本字段、2个按钮和一个通过编程创建的imageview

-(UIButton*) formatButton:(UIButton*)button
{
button.layer.cornerRadius = 10;
button.clipsToBounds = YES;
button.layer.borderColor=[[UIColor lightGrayColor] CGColor];
button.layer.borderWidth=1.0;
[button.titleLabel setTextAlignment:NSTextAlignmentCenter];
[button.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-UltraLight" size:20]];
[button setTitle:@"0" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

return button;
}

-(UITextField*)formatTextField:(UITextField*)textField
{
[textField setFont:[UIFont fontWithName:@"HelveticaNeue-UltraLight" size:20]];
textField.backgroundColor=[UIColor whiteColor];
textField.layer.borderColor=[[UIColor lightGrayColor] CGColor];
textField.layer.cornerRadius = 10;
textField.layer.borderWidth=1.0;
[textField setTextAlignment:NSTextAlignmentCenter];
textField.clipsToBounds=YES;
textField.text=@"";
textField.enabled=NO;

return textField;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemCellID" forIndexPath:indexPath];
// Configure the cell...
OrderedProduct *orderedProduct=self.orderedProductsArray[indexPath.row];
//NSLog (@"ordered Product %@",orderedProduct.productID);

UITextField *qualityField=[[UITextField alloc] initWithFrame:CGRectMake(113,23,324,30)];
qualityField=[self formatTextField:qualityField];
[cell addSubview:qualityField];

UITextField *sizeField=[[UITextField alloc] initWithFrame:CGRectMake(445, 24, 142, 30)];
sizeField=[self formatTextField:sizeField];
[cell addSubview:sizeField];

UITextField *totalPriceField=[[UITextField alloc] initWithFrame:CGRectMake(786,24,137,30)];
totalPriceField=[self formatTextField:totalPriceField];
[cell addSubview:totalPriceField];

UIButton *quantityButton=[[UIButton alloc] initWithFrame:CGRectMake(595,24,60,30)];
quantityButton=[self formatButton:quantityButton];
[cell addSubview:quantityButton];

UIButton *priceButton=[[UIButton alloc] initWithFrame:CGRectMake(663,24,119,30)];
priceButton=[self formatButton:priceButton];
[cell addSubview:priceButton];

UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(5,15,100,50)];
[cell addSubview:imageView];

UIButton *removeButton=(UIButton*)[cell viewWithTag:kRemoveButton];

if (self.selectedOrder.status==[NSNumber numberWithInt:kOrderStatusProvisional])
{
    quantityButton.enabled=YES;
    quantityButton.backgroundColor=[Settings getInstance].enabledButtonColor;
    [quantityButton addTarget:self action:@selector(quantityButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    priceButton.enabled=YES;
    priceButton.backgroundColor=[Settings getInstance].enabledButtonColor;
    removeButton.hidden=NO;
    [removeButton addTarget:self action:@selector(removeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
}
else
{
    quantityButton.enabled=NO;
    quantityButton.backgroundColor=[Settings getInstance].disabledButtonColor;
    priceButton.enabled=NO;
    priceButton.backgroundColor=[Settings getInstance].disabledButtonColor;
    removeButton.hidden=YES;
}

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setCurrencyCode:@"GBP"];
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
imageView.image=[self.imageCache objectForKey:orderedProduct.product.productImageName];

UITapGestureRecognizer *tgr=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTapped:)];
imageView.userInteractionEnabled=YES;
[imageView addGestureRecognizer:tgr];
qualityField.text=orderedProduct.product.name;
sizeField.text=orderedProduct.product.productSize.productSize;
quantityButton.titleLabel.text=[NSString stringWithFormat:@"%@",orderedProduct.quantity];
[quantityButton setTitle:[NSString stringWithFormat:@"%@",orderedProduct.quantity] forState:UIControlStateNormal];

float price=[orderedProduct.price integerValue]/100; // server price is in pennies
float totalPrice=price*[orderedProduct.quantity integerValue];
[priceButton setTitle:[numberFormatter stringFromNumber:[NSNumber numberWithFloat:price]] forState:UIControlStateNormal];

totalPriceField.text=[numberFormatter stringFromNumber:[NSNumber numberWithFloat:totalPrice]];

return cell;
}
还不能发布图片,下面是对仪器所说内容的粗略描述

快速增长

B代3.64MB

VM:UILabel(CALayer)964KB

VM:UITextFieldLabel(CALayer)792KB


VM:CoreAnimation 788KB

您在项目中是否使用ARC?对不起,是的,我正在使用ARC。