automatic-ref-counting

Container UIViewController Not Releasing it's Child View Controllers

懵懂的女人 提交于 2019-12-02 17:41:59
I have a custom container UIViewController that has six child UIViewControllers, and a set of tabs that the user interacts with to switch between the child view controllers. The problem is when my container view controller is released the child view controllers are not. I have verified that the child view controllers are not released by adding some debugging code to their dealloc methods, and they are released as long as their view's are not added to the container view controller's view. Below is an a excerpt of the code I'm using to create my custom container view controller. The

iOS bridge vs bridge_transfer

五迷三道 提交于 2019-12-02 16:37:23
I'm confused with bridge and bridge_transfer , is this correct? -(void)getData{ ABAddressBookRef addressBook = ABAddressBookCreate(); NSArray *allPeople = (__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook); NSString *name; for ( int i = 0; i < [allPeople count]; i++ ) { name = (__bridge_transfer NSString *) ABRecordCopyValue((__bridge ABRecordRef)[allPeople objectAtIndex:i], kABPersonFirstNameProperty); } CFRelease(addressBook); allPeople = nil; } Is there anyone who can explain me how to use them? If you have automatic-reference-counting (ARC) turned on, the code is

Am I correctly creating and passing this C array to Objective-C method and referencing it with a property?

我怕爱的太早我们不能终老 提交于 2019-12-02 16:11:15
问题 I created a C array like this: unsigned char colorComps[] = {2, 3, 22, 55, 9, 1}; which I want to pass to an initializer of an Objective-C object. So I think I have to put the array on the heap: size_t arrayByteSize = numColorCompVals * sizeof(unsigned char); unsigned char *colorCompsHeap = (unsigned char*)malloc(arrayByteSize); Then I have to write my first "stack memory array" to the heap array in for loop: for (int i = 0; i < numColorCompVals; i++) { colorCompsHeap[i] = colorComps[i]; }

What does “Receiver type 'CALayer' for instance message is a forward declaration” mean here?

你离开我真会死。 提交于 2019-12-02 16:02:04
I'm porting a block of code from an iOS4 project to iOS5 and I'm having some troubles with ARC. The code generates a PDF from a screen capture. PDF Generation Code UIView *captureView; ... NSMutableData *pdfData = [NSMutableData data]; UIGraphicsBeginPDFContextToData(pdfData, captureView.bounds, nil); UIGraphicsBeginPDFPage(); CGContextRef pdfContext = UIGraphicsGetCurrentContext(); [captureView.layer renderInContext:pdfContext]; UIGraphicsEndPDFContext(); The renderInContext line [captureView.layer renderInContext:pdfContext]; generates the following error. Automatic Reference Counting issue

strong @property with __attribute__((NSObject)) for a CF type doesn't retain

匆匆过客 提交于 2019-12-02 15:55:16
UPDATE: This issue has been fixed as of Xcode 4.6! This technique now works as intended again. However, make sure to read the notes at the top of Rob Napier's excellent answer before you use it in your code. ORIGINAL POST (ARC, Xcode 4.3.1, iOS 5.1) I have a strong property of a CF type (CGImage) that I want to be automatically managed by ARC using __attribute__((NSObject)) (as in having retain & release in the synthesized setter, and it being nil'ed in dealloc), but it doesn't work: the object is not retained when I assign the property. A minimal example to reproduce: @interface TestClass :

implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC

感情迁移 提交于 2019-12-02 15:48:40
What does this mean and what alternative do I have? implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC I am porting an Xcode3 project to iOS5 wich uses AudioSessionInitialize like this AudioSessionInitialize(NULL, NULL, NULL, self); where self here is a ViewController. Joshua Weinberg You can't do implicit casts to void* anymore, AudioSessionInitialize(NULL, NULL, NULL, objc_unretainedPointer(self)); should do the trick. EDIT: Historical point, the answer above was from before the __bridge casts were finalized. In modern code the correct answer is that provided by

Did the Target-Action design pattern became bad practice under ARC?

断了今生、忘了曾经 提交于 2019-12-02 15:09:24
For years I've been following a great pattern called Target-Action which goes like this: An object calls a specified selector on a specified target object when the time comes to call. This is very useful in lots of different cases where you need a simple callback to an arbitrary method. Here's an example: - (void)itemLoaded { [specifiedReceiver performSelector:specifiedSelector]; } Under ARC it now turns out that doing something like this all of a sudden became dangerous. Xcode throws a warning that goes like this: PerformSelector may cause a leak because its selector is unknown Of course the

Delegate assignment causes EXC_BAD_ACCESS

我的未来我决定 提交于 2019-12-02 13:11:38
I am trying to create a delegate for an NSTextField in my view controller, but the program crashes with EXC_BAD_ACCESS . Why does this happen? I read that I am calling a non-existent object, but I don´t know what does not exist. I am using ARC. This is how the delegate object is created in my view controller: #import <Cocoa/Cocoa.h> #import "Delegate.h" @interface ViewController : NSViewController <NSTextFieldDelegate>{ } @end -- #import "ViewController.h" @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSTextField* textField1 = [[NSTextField alloc] initWithFrame

ARC instance variable retain release

五迷三道 提交于 2019-12-02 12:19:03
If we have .h file like this: @interface TestViewController : UIViewController { __weak NSObject *object; } @end and methods in .m file like this: - (void)viewDidLoad { [super viewDidLoad]; NSObject *localObject = [[NSObject alloc] init]; NSLog(@"%ld", CFGetRetainCount((__bridge CFTypeRef)localObject)); object = localObject; NSLog(@"%ld", CFGetRetainCount((__bridge CFTypeRef)object)); NSLog(@"%ld", CFGetRetainCount((__bridge CFTypeRef)localObject)); } Then we get the following output for retain count: 1 2 1 My question is why does the retain count gets incremented to 2 on "object" when it is

Swift class de-initialized at end of scope instead of after last usage

让人想犯罪 __ 提交于 2019-12-02 11:50:20
I've asked this question asking about the guarantees of the lifetime of a reference in a local variable and was referred to this thread in which the exact semantics of the lifetime of references to class instances were discussed. AFAICT from that thread, a class instance may be de-initialized right after the last usage of a variable containing the last reference, even before other expressions in the same statement are evaluated. It is argued there that allowing this behavior is necessary to prevent creating unnecessary copies in copy-on-write data structures, which I can follow. This brought