iphone - iOS 4 GCD questions -


I've seen some presentations of the WWDC 2010 and block and read most of the concurrency documents and Grand Central Dispatch uses blocks with serial lines to about a few questions in a iOS 4 project to me which is a dictionary of Scrolwu and image information - like URLs for images and so on. I want to use GCD and blocks to download images and in my scrollwid so that the main thread is not blocked. I wrote the following code seems to work:

  (for pictures Ansreepshn * dict) {Preshk_sisnk (image_queue, ^ {NSString * urlString = [dict objectForKey: @ "url"] ; NSURL * url = [NSURL URLWithString: urlString]; NSData * imageData = [[NSData alloc] initWithContentsOfURL: url] UIImage * image = [UIImage imageWithData: imageData]; UIImageView * Start imageView = // see the image; Dispatch_async (dispatch_as_main_queue (), ^ {[self.scrollView addSubview: imageView];}); [image data release];}); }  

I have two questions:

  1. According to concurrency guide, should I hold the variable scope of without - in my code, I can capture an object that is an NSDictionary * object. If I do not have permission to capture it then how should I write code? Can one block only capture the variable from the scope used?

  2. What if I leave the existing view controller before bringing all the views through a serial transmission queue? I do not think that they know that the view controller that they have created has gone, what happens when they execute the full handler, where I insert the image view in my scrollwid on the main scroll? Is this an error or what is the reason? And how can I cancel any remaining operations in the serial queue when my view controller disappears?

"post-text" itemprop = "text">
  1. Though it is a difficult the point is, it's important to understand that concurrency Guide is trying to do what you say: indicators are scalar type so you can capture pointers within blocks you want ... but you They have to know about the life of those memory, which they point out! NSDRIATION * is a type of ID, and when you refer to an ID in a block, it takes responsibility for maintaining the runtime ID if the block is copied (which it is by dispatch_assicant) and then issuers When the block itself has been canceled and yes, a block refers only to the variable that is referenced within it.

  2. As you now know that the Async Block has retained itself, it should be clear (er) that (modules memory management errors) not "disappear" your ViewController Can not be blocked until it can be blocked. So this accident is not going to happen - but you are right that you really want a way to cancel this kind of asynchronous work, when you are actually planning to use the result. A simple-on-effect pattern is to perform a test at the beginning of its async block which checks to see that the work should still be done.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -