Am I investing too much in my NSMutableArray? Please help!

So, I am making the application very fast, and although this is not the best solution, it seems to work for the most part. So I have a simple image that pulls an image from NSMutableArray arr. I create an array and populate it inside ViewDidLoad this way:

arr = [[NSMutableArray alloc] init];

[arr addObject:[UIImage imageNamed:@"181940jpg"]];
[arr addObject:[UIImage imageNamed:@"168026.jpg"]];
[arr addObject:[UIImage imageNamed:@"168396.jpg"]];
[arr addObject:[UIImage imageNamed:@"168493_.jpg"]];

And I continue to do this for 130 images. Obviously, this is a large array. I don’t know if this is really a really bad way, but if so, I am open to suggestions! When I look through the array using simple back and forward buttons, pulling images from the array based on a simple counter variable, everything works fine until the 45-ish image. The application breaks up and the console says this:

* ERROR: ImageIO header 'ImageProviderCopyImageBlockSetCallback' is not CFDictionary ...

Would it help me if I broke my images into separate arrays? Am I just putting too much into an array? What I'm missing here, believe me, I'm all ears.

thank

EDIT: here is more info

This is how I sift the array using the UISegmentedControl set at the top of the screen:

  -(void) pickedOne{
if(segmentedControl.selectedSegmentIndex == 1){
    NSLog(@"hey");
    if(position < [arr count]-1){

        position++;//This is my global counter variable
        UIImage * img = [arr objectAtIndex:position];
        [imageView setImage:img];
        [img release];
    }       

}else if(segmentedControl.selectedSegmentIndex ==0){

    if(position >0){

        position--;
        UIImage * img = [arr objectAtIndex:position];
        [imageView setImage:img];
        [img release];
    }       

}
  }

This is not a memory management problem, but again, I do not consider myself a professional in this in any way ...

+3
source share
1 answer

In terms of a mutable array, what you insert into it is a pointer to some other object. These are the other objects that you need to worry about, and, yes, you have too many of them (most likely not).

  • : ImageIO 'ImageProviderCopyImageBlockSetCallback' header CFDictionary...

, ? ? , , .

, , - API- ImageIO.

, , , :

    UIImage * img = [arr objectAtIndex:position];
    [imageView setImage:img];
    [img release];

, release ; . objectAtIndex: , UIView / .

release ( )!

. 42K ( , ), 130 ~ 6 , .

.

+4

Source: https://habr.com/ru/post/1791769/


All Articles