automatic-ref-counting

ARC: __bridge versus __bridge_retained using contextInfo test case

有些话、适合烂在心里 提交于 2021-01-27 05:54:27
问题 Consider this ARC code: - (void)main { NSString *s = [[NSString alloc] initWithString:@"s"]; [NSApp beginSheet:sheet modalForWindow:window modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:context:) contextInfo:(__bridge void *)s ]; } - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode context:(void *)context { NSString *s = (__bridge_transfer NSString *)context; } Question: on line 7, should __bridge be used, or __bridge_retained , or does it not matter,

ARC: __bridge versus __bridge_retained using contextInfo test case

和自甴很熟 提交于 2021-01-27 05:54:24
问题 Consider this ARC code: - (void)main { NSString *s = [[NSString alloc] initWithString:@"s"]; [NSApp beginSheet:sheet modalForWindow:window modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:context:) contextInfo:(__bridge void *)s ]; } - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode context:(void *)context { NSString *s = (__bridge_transfer NSString *)context; } Question: on line 7, should __bridge be used, or __bridge_retained , or does it not matter,

Weak method argument semantics

╄→尐↘猪︶ㄣ 提交于 2020-04-10 03:14:11
问题 Is there any way to specify that a particular method argument has weak semantics? To elaborate, this is an Objective-C sample code that works as expected: - (void)runTest { __block NSObject *object = [NSObject new]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self myMethod:object]; }); // to make sure it happens after `myMethod:` call dispatch_async(dispatch_get_main_queue(), ^{ object = nil; }); } - (void)myMethod:(__weak id)arg0 { NSLog(@"%@", arg0); //

__strong and __weak keyword placement - Objective-C

◇◆丶佛笑我妖孽 提交于 2020-02-13 02:25:50
问题 The compiler seems to have no problem with the two following declarations: NSObject * __weak weakThing; __weak NSObject *anotherWeakThing; Is there a difference between the two? Is the behavior like the const keyword? I ask because Xcode's warning generally suggest ... SomeDataType * __weak / __strong ... when you've goofed something up. So I've tried to follow this pattern, but wondered if there was a difference at all. 回答1: No, there is no difference. With the const keyword, there are

__strong and __weak keyword placement - Objective-C

耗尽温柔 提交于 2020-02-13 02:25:29
问题 The compiler seems to have no problem with the two following declarations: NSObject * __weak weakThing; __weak NSObject *anotherWeakThing; Is there a difference between the two? Is the behavior like the const keyword? I ask because Xcode's warning generally suggest ... SomeDataType * __weak / __strong ... when you've goofed something up. So I've tried to follow this pattern, but wondered if there was a difference at all. 回答1: No, there is no difference. With the const keyword, there are

iOS: __weak vs (weak)

大兔子大兔子 提交于 2020-02-01 05:04:27
问题 Are there a differences between these two lines of code? __weak IBOutlet UITextField *usernameField; @property (weak) IBOutlet UITextField *usernameField; What if you declare either of these in interface section of the .h or the .m files? 回答1: Yes. The first example declares a weak instance variable called usernameField , but the second declares a weak property called usernameField , and an instance variable called _usernameField that is accessed by the property. If you declare it in an

Conversion to Automatic Reference Counting (ARC): 'Use of undeclared identifier' errors

时光毁灭记忆、已成空白 提交于 2020-01-31 15:23:09
问题 In one of the very big projects I used auto-synthesized properties everywhere: //MyClass.h file: @interface MyClass : NSObject @property (nonatomic, retain) NSString *deviceName; @property (nonatomic, retain) NSString *deviceID; @end //MyClass.m file: #import "MyClass.h" @implementation ApplicationStatus // no @synthesize used at all. -(void)dealloc{ [_deviceName release]; // gives errors only while converting to ARC with LLVM 5.0 [_deviceID release]; [super dealloc]; } @end The code above

blocks and ARC - copy or crash with release build (caused by optimization level)

独自空忆成欢 提交于 2020-01-31 08:38:54
问题 I'm using Xcode 4.3.3 and developing for iOS 5.0+. In development of an ARC iOS application, I've started using blocks as a callback mechanism for asynchronous operations. The app works fine in the simulator and on the device. Then I ran it the profiler for the first time, and it started crashing on me nearly right away - in particular, an EXC_BAD_ACCESS when trying to invoke the first callback block. After a little investigation, it was clear the difference in behavior was because the

Memory is not released during perform batch updates in CollectionView

£可爱£侵袭症+ 提交于 2020-01-25 09:06:01
问题 I've been working on a project of using two UICollectionView 's I have on that is the MainViewController with full screen cells that scroll horizontally and one that sits on that full screen cell and scrolls vertically. I have a functionality that adds as well as deletes cells. When a user taps and one of the pages of the MainViewController is deleted using the code below the memory that grew as cells were added is still being retained. Is there something Im doing wrong. All of my delegates

Memory is not released during perform batch updates in CollectionView

你说的曾经没有我的故事 提交于 2020-01-25 09:05:30
问题 I've been working on a project of using two UICollectionView 's I have on that is the MainViewController with full screen cells that scroll horizontally and one that sits on that full screen cell and scrolls vertically. I have a functionality that adds as well as deletes cells. When a user taps and one of the pages of the MainViewController is deleted using the code below the memory that grew as cells were added is still being retained. Is there something Im doing wrong. All of my delegates