2
votes

I am loading images in UIWebview using the following code. For each image (while scrolling my scrollview) a function is called to load the image. The problem is that when I am continuously scrolling up to 30 images the application crashes. What may be the reason? My images are 1300 by 1200 pixels. Please help me find a solution.

- (void) loadCatalogImage 
{
    @try{
//  if(imgView.image != nil)
//      return;
    //  [global_imgProgress startAnimating];
    //NSLog(@"image loading at = %@, %d", baseURL, 2 + pageNo);
    NSAutoreleasePool *pool;
    pool = [[NSAutoreleasePool alloc] init];

    //NSArray *array = [global_ContentString componentsSeparatedByString:@"@@#"];
    NSArray *array1 = [catalogURL componentsSeparatedByString:@"&"];
    //NSLog(@"baseURL = %@",baseURL);
    NSLog(@"loading catalog image(method: loadCatalogImage).......%@%@",baseURL, [[[array1 objectAtIndex:0] componentsSeparatedByString:@"##"] objectAtIndex:0]); 

    zoomedImageURL = [NSString stringWithFormat:@"%@%@", baseURL, [[[array1 objectAtIndex:0] componentsSeparatedByString:@"##"] objectAtIndex:1]];
//  NSLog(@"Catalog ZOOM URL = %@", zoomedImageURL);//[[array1 objectAtIndex:0] componentsSeparatedByString:@"##"]);//[[[array objectAtIndex:[[global_CatalogRef objectAtIndex:pageNo] intValue]] componentsSeparatedByString:@"##"] objectAtIndex:3]);
    [zoomedImageURL retain];

    NSLog(@"aaaaaaa = %@",zoomedImageURL);
    [webView loadRequest:
        [NSURLRequest requestWithURL:
            [NSURL URLWithString:
                [NSString stringWithFormat:@"%@%@",baseURL, [[[array1 objectAtIndex:0] componentsSeparatedByString:@"##"] objectAtIndex:1]
                ]
            ]]
        ];

    }
}
3
What stack trace or crash info do you get on the console? Is your project producing any warnings?occulus
Just FYI : You're not releasing the pool you're creating.deanWombourne
@Madhumitha: What was your solution?testing

3 Answers

1
votes

Your images are 1300 x 1200 and you're loading 30 of them? You may WILL be running out of memory. If your app is ignoring memory warnings, and hogging up memory, the iOS system may be forcing your app to quit. As I mention in my comment below, that many images, that size, would be about 180megs. Far too big.

Do you really need to deliver such large images to an iphone app, and so many of them?

1
votes

Any app that loads up enough resources to occupy so much memory will crash. Apple has several demo projects that deal specifically with loading a large image by breaking it down into smaller bits ci suggest you take a look at them.

0
votes

Can you put a crash log please? If possible Enable the Environment variable 'NSZombieEnabled' and then run the application and have a look at the crash log. This will help us to get the exact problem. By the way why are you creating and retaining "zoomedImageURL"?