views:

19

answers:

1

I am using the LeavesView Class available on GitHub by Tom Brow.

On the iPad, I have 23 images at 1024x768 ranging from 200-500KB (JPG's). I have compressed the images as much as I could without losing quality. For some reason, when I init with the list of images, the memory drops significantly, and ultimately crashes. Here's some code:

- (id)init {
    if (self = [super init]) {
        images = [[[NSArray alloc] initWithObjects:
              [UIImage imageNamed:@"001.jpg"],
              [UIImage imageNamed:@"002.jpg"],
              [UIImage imageNamed:@"003.jpg"],
              [UIImage imageNamed:@"004.jpg"],
              [UIImage imageNamed:@"005.jpg"],
              [UIImage imageNamed:@"006.jpg"],
              [UIImage imageNamed:@"007.jpg"],
              [UIImage imageNamed:@"008.jpg"],
              [UIImage imageNamed:@"009.jpg"],
              [UIImage imageNamed:@"010.jpg"],
              [UIImage imageNamed:@"011.jpg"],
              [UIImage imageNamed:@"012.jpg"],
              [UIImage imageNamed:@"013.jpg"],
              [UIImage imageNamed:@"014.jpg"],
              [UIImage imageNamed:@"015.jpg"],
              [UIImage imageNamed:@"016.jpg"],
              [UIImage imageNamed:@"017.jpg"],
              [UIImage imageNamed:@"018.jpg"],
              [UIImage imageNamed:@"019.jpg"],
              [UIImage imageNamed:@"020.jpg"],
              [UIImage imageNamed:@"021.jpg"],
              [UIImage imageNamed:@"022.jpg"],
              [UIImage imageNamed:@"cover.jpg"],
              nil] autorelease];
    }
    return self;
}

Now, in this piece of code, I've used autorelease. I have also tried:

-(void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    NSLog(@"memory warning");
    LeavesCache *lv =[LeavesCache alloc];
    [lv flush];
    [lv release];
    //[images release];
}

and of course, in this example, I just use images and not other objects I use in the view:

-(void)viewDidUnload {
    [super viewDidUnload];
    images = nil;
}
-(void)dealloc {
    [images release];
    [super dealloc];
}

When I use autorelease for the image array, [images release]; is commented out, and vice versa, if I dont use autorelease, I use release in dealloc.

Now, when I pop the view, the memory is regained as expected. It's just that images seems to be a HOG when in use, and I dont know another way around not using the image array.

Any help would be uch appreciated.

A: 

I was able to resolve my emory leaks with:

[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"001" ofType:@"jpg"]]

I saw a significant amount f memory recovered by using this method, and was able to stop the crases, hope this will help someone else!

AWright4911