Ios 在iphone中删除ARC时应用程序崩溃

Ios 在iphone中删除ARC时应用程序崩溃,ios,iphone,objective-c,Ios,Iphone,Objective C,我的应用程序是基于ARC的,出于某种原因我删除了ARC。现在UICollectionView中的应用程序崩溃了,我不知道如何释放对象,它是img_数组 这是我的密码: - (void)viewDidLoad { isShown = false; [self.navigationController setNavigationBarHidden:YES]; [super viewDidLoad]; // Do any additional setup afte

我的应用程序是基于ARC的,出于某种原因我删除了ARC。现在UICollectionView中的应用程序崩溃了,我不知道如何释放对象,它是img_数组

这是我的密码:

 - (void)viewDidLoad

{
    isShown = false;
    [self.navigationController setNavigationBarHidden:YES];

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    img_ary=[[NSMutableArray alloc]init];
    img_ary= [NSMutableArray arrayWithObjects:@"car-image.png",@"image.png",@"car-image.png",@"image.png",@"car-image.png",@"image.png",@"car-image.png",@"image.png", nil];
    [self collectioncreate];
    img1_ary=[[NSArray alloc]init];
    img1_ary=[NSArray arrayWithObjects:@"small-slider-images.png",@"small-slider-image-2.png",@"small-slider-image-2.png",@"small-slider-images.png",@"small-slider-image-2.png",@"small-slider-image-2.png",@"small-slider-images.png",@"small-slider-image-2.png",@"small-slider-image-2.png",@"small-slider-images.png",@"small-slider-image-2.png",@"small-slider-image-2.png",@"small-slider-images.png",@"small-slider-image-2.png",@"small-slider-image-2.png", nil];

    nameArray = [[NSMutableArray alloc]init];
   // nameArray = [NSMutableArray arrayWithObject:@"Top 5",@"Call",@"car",@"Buy",@"View Tutorial",@"MOI",@"Terms & Conditions",@"Private Policy",nil];
    [nameArray addObject:@"Top 5"];
    [nameArray addObject:@"Call"];
    [nameArray addObject:@"Car"];
    [nameArray addObject:@"Buy"];
    [nameArray addObject:@"View Tutorial"];
    [nameArray addObject:@"MOI"];
    [nameArray addObject:@"Terms & Conditions"];
    [nameArray addObject:@"Private Policy"];
    [nameArray addObject:@"About Us"];
    [nameArray addObject:@"Corporate Account"];
    [nameArray addObject:@"4th Motor Envioroment"];
    [nameArray addObject:@"Help & FAQ"];
    [nameArray addObject:@"Contact Us"];
    [nameArray addObject:@"Track Your Order"];
    [nameArray addObject:@"Sell on $ Motor"];
    [nameArray addObject:@"Adjust your Car"];

    UIImage *searchFieldImage = [[UIImage imageNamed:@"search-1.png"]
                                 resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 17, 10)];

    [search_bar setSearchFieldBackgroundImage:searchFieldImage forState:UIControlStateNormal];



    //[self createScrollView1];
    //[self createButton1];

}


-(void)collectioncreate1
{

    cellNib = [UINib nibWithNibName:@"caracell" bundle:nil];
    [collectionview registerNib:cellNib forCellWithReuseIdentifier:@"caracell"];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setItemSize:CGSizeMake(279, 244)];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    [collectionview setCollectionViewLayout:flowLayout];

    collectionview.delegate=self;
    collectionview.dataSource=self;
    [collectionview reloadData];
}


-(void)collectioncreate
{

    cellNib = [UINib nibWithNibName:@"carecell" bundle:nil];
    [collectionview registerNib:cellNib forCellWithReuseIdentifier:@"carecell"];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setItemSize:CGSizeMake(279, 244)];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    [collectionview setCollectionViewLayout:flowLayout];

    collectionview.delegate=self;
    collectionview.dataSource=self;
    [collectionview reloadData];

}

- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
    return 10;
}

-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [img_ary count];
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //     [self resetIdleTimer];
    carecell * cell = (carecell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"carecell" forIndexPath:indexPath] ;
    if(cell==nil)
    {

        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"carecell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

    }
    cell.car_img.image = [UIImage imageNamed:[img_ary objectAtIndex:indexPath.row]];
    **********************AT This point app Crash *********************
    return cell;

}
请帮忙,
提前感谢

此代码不正确:

img_ary=[[NSMutableArray alloc]init];
img_ary= [NSMutableArray arrayWithObjects:@"car-image.png",@"image.png",@"car-image.png",@"image.png",@"car-image.png",@"image.png",@"car-image.png",@"image.png", nil];
它当前创建了两个NSMutableArray(两次调用
alloc
),泄漏了第一个,而没有保留第二个

您应该创建一个NSMutableArray,并通过保留它来保持对它的强引用(可以通过
alloc
retain
,但不能同时通过这两种方式)

(编辑)


另外,您可能真的应该使用ARC。这很有帮助。

如果你的图灵离弧意味着

就这么做吧

@property (nonatomic,retain) NSMutableArray *img_ary;
并在实施中

self.img_ary= [NSMutableArray arrayWithObjects:@"car-image.png",@"image.png",@"car-image.png",@"image.png",@"car-image.png",@"image.png",@"car-image.png",@"image.png", nil];

并删除这一行
img_ari=[[NSMutableArray alloc]init]
,它在ARC和非ARC中都是浪费。

你知道
NSMutableArray
NSArray
之间的区别吗?是的,但当我使用NSArray@8unty我不知道在哪里发布obj?为什么要关闭ARC?您必须在应用程序中的任何地方插入手动内存管理代码。这是一个糟糕的主意。我在@property.but crash中加入了非原子的、强的。当我使用arc时,它会运行为什么?但是当我在设备中使用arc时,它会崩溃除非你使用self.img_ary或[self setImg__ary:],否则你根本就不用你的属性。除非您实际使用它,否则您声明的内容没有任何区别。如果您的代码在ARC打开时崩溃,并且在ARC关闭时崩溃,您可能应该调试代码,而不是打开和关闭ARC。