views:

34

answers:

0

I'm implementing the lazy table images algorithm similar to how facebook does. I got this from an example given by apple: http://developer.apple.com/iphone/library/samplecode/LazyTableImages/Introduction/Intro.html

It works fine up until I start getting memory warnings. My images are stored in a dictionary, that links up a key to an image. In my program, when my table of images gets large (>500), I start experiencing issues. As I'm scrolling through the table loading up each image, I'll receive my first memory warning. In didReceiveMemoryWarning, i release my dictionary of images, and reallocate a blank dictionary. When I run it with performance tools to check leaks, I see that when the app receives a memory warning, the total allocated bytes jumps back down to around where it was before I received the warning. If I continue loading up the images, I get a memory warning faster, when less bytes are allocated than before. Again the images get released and the byte count starts off low again. After the 3rd warning, memory warning level 2, the app crashes. Should I be releasing something other than just my images???

Here's how I implement the dictionary of images.

I copied the iconDownloader files from the apple source code and changed a few things. To start the downloading of the images in iconDownloader.m i do

self.activeDownload = [NSMutableData data];

// alloc+init and start an NSURLConnection; release on completion/failure

NSString *url = (URL OF IMAGE HERE)

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:
                         [NSURLRequest requestWithURL:
                          [NSURL URLWithString:url]] delegate:self];

self.imageConnection = conn;

[conn release];

when the request finishes i do UIImage *image = [[UIImage alloc] initWithData:self.activeDownload];

self.activeDownload = nil;


// Release the connection now that it's finished
self.imageConnection = nil;

// call our delegate and tell it that our icon is ready for display
if (image != nil)
    [delegate appImageDidLoad:self.indexPathInTableView withImage:image forUser:avId];
[image release];

in the delegate method back in my tableViewController i simply set the image for the cell and then [dictOfImages setObject:image forKey:avId]; to add it to my dict