ARC and bridged cast

I agree that the description is confusing. Since I just grasped them, I’ll try to summarize: (__bridge_transfer <NSType>) op or alternatively CFBridgingRelease(op) is used to consume a retain-count of a CFTypeRef while transferring it over to ARC. This could also be represented by id someObj = (__bridge <NSType>) op; CFRelease(op); (__bridge_retained <CFType>) op or alternatively … Read more

Why isn’t my weak reference cleared right after the strong ones are gone?

From the assembly code it can be seen that accessing weakPtr generates a objc_loadWeak call. According to the Clang documentation, objc_loadWeak retains and autoreleases the object and is equivalent to id objc_loadWeak(id *object) { return objc_autorelease(objc_loadWeakRetained(object)); } This (hopefully) explains why both if(strongPtr == weakPtr) … and NSLog(@”weakPtr: %@”, weakPtr); create additional autoreleased references. This … Read more

What’s the difference between performSelectorOnMainThread: and dispatch_async() on main queue?

By default, -performSelectorOnMainThread:withObject:waitUntilDone: only schedules the selector to run in the default run loop mode. If the run loop is in another mode (e.g. the tracking mode), it won’t run until the run loop switches back to the default mode. You can get around this with the variant -performSelectorOnMainThread:withObject:waitUntilDone:modes: (by passing all the modes you … Read more

iOS – Merging two images of different size

This is what I’ve done in my app, but without using UIImageView: UIImage *bottomImage = [UIImage imageNamed:@”bottom.png”]; //background image UIImage *image = [UIImage imageNamed:@”top.png”]; //foreground image CGSize newSize = CGSizeMake(width, height); UIGraphicsBeginImageContext( newSize ); // Use existing opacity as is [bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; // Apply supplied opacity if applicable [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.8]; UIImage *newImage = … Read more

How does the NSAutoreleasePool autorelease pool work?

Yes, your second code snippit is perfectly valid. Every time -autorelease is sent to an object, it is added to the inner-most autorelease pool. When the pool is drained, it simply sends -release to all the objects in the pool. Autorelease pools are simply a convenience that allows you to defer sending -release until “later”. … Read more