views:

32

answers:

1

I've been reading an article about caching images in iPhone OS, and they pointed out this code snippet:

NSData *urlData = [NSData dataWithContentsOfURL:aURL];

When I do something like this, does the whole big image data get sucked into the memory? Or will the image data go into memory as soon as that urlData object is actually used? Right now I think they were wrong and this code snippet immediately brings the whole data into memory. My 10 Megapixel image causes the app to freeze and finally crash. If that snipped would not load the image into memory before usage, this should not happen, right?

A: 

Right, your code snippet slurps the file into memory (into one big malloc).

Your question is a bit unclear what you are trying to accomplish: Save build time? Prefetch images in your app? Cache images for reuse?

Nikolai Ruhe