views:

32

answers:

1

What exactly happens when I do this...?

NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL urlWithString:@"..."]];

Does it immediately go out to the Internet, gets all the data at the URL, returns, and goes to the next line? Or does it set things up, and the data is read later when the bytes of NSData are requested? If the data is read later, is all the data read in one shot? Or is the data read in piecemeal as the app needs them?

My basic problem is that I have a very large XML file to parse. If I set up an NSData object and parse it through NSXMLParser, will the app blow up because the XML data is too large? Or does the app "do the right thing" and parses the XML as the data bytes stream in?

Thanks!

A: 

It will immediately go out to the network and fetch that data for you. Your application will block until the request has finished. It is usually not a good idea to do this from the main thread because the user interface will block which makes your application unresponsive.

If you use this method to load your large XML file then the whole file be read into memory and the app will block until that is done.

St3fan