automatic-ref-counting

Do system object delegates in ARC need to be set to nil?

断了今生、忘了曾经 提交于 2019-12-06 00:36:14
An app crashes sometimes with error objc_object::release() . The Apple Developer Technical Support mentioned this: Remember that you should always do something like _tableView.delegate = nil; in your -dealloc methods, even if you are using ARC. For compatibility reasons system objects use unsafe_unretained references to implement delegation, instead of the preferred modern replacement weak . Does that mean that I have to set the delegates of system objects to nil when the view controller is about to be released? class MyViewController: UIViewController { deinit { tableView.delegate = nil

ARC unavailable methods in Swift

偶尔善良 提交于 2019-12-06 00:10:27
I was able to see an interesting case using Estimote nearables SDK They have a class ESTNearable with property called zone . // ENUM typedef NS_ENUM(NSInteger, ESTNearableZone ) { ESTNearableZoneUnknown = 0, ESTNearableZoneImmediate, ESTNearableZoneNear, ESTNearableZoneFar, }; // CLASS @interface ESTNearable : NSObject <NSCopying, NSCoding> // ... @property (nonatomic, assign, readonly) ESTNearableZone zone; // ... @end So when I try to use this method in Swift , compiler fails with that error: As I understand there is some kind of compiler bug and for some reason it believes that I want to

Convert App to ARC while ignoring files?

℡╲_俬逩灬. 提交于 2019-12-05 22:35:33
问题 I want to convert my app to ARC but I have some external librarys and frameworks that are not complaint with ARC. I know when yous start a new project using ARC, you can later specify which files to ignore. But can you do this when upgrading an existing app to ARC? 回答1: in XCode, go to your active target and select the Build Phases tab. In the Compiler Flags column, set -fno-objc-arc for each of the files you don't want ARC EDIT: Also, to have the opposite behavior, I mean to use a file that

Playing around with ARC: Force release irritation?

点点圈 提交于 2019-12-05 21:27:28
I am currently playing around with ARC a bit to get some things figured out, before starting to do the actual work. I did setup this code: NSNumber* n = [[NSNumber alloc] initWithInt:3]; __weak NSNumber* weakN = n; n = nil; NSLog(@">>>: %@ %@", n, weakN); I expected n and weakN to be nil, as n = nil; should trigger a release in my eyes? Unfortunately it doesn't. The output is ">>>: (null) 3". What am I missing here? Another thing is, that I am pretty sure, the below code was giving me a hard time when starting with arc: __weak NSNumber* weakN2 = [[NSNumber alloc] initWithInt:3]; NSLog(@">>>: %

dispatch_once call causes crash

徘徊边缘 提交于 2019-12-05 20:54:25
dispatch_once call causes crash (in simulator) after I've converted my project to ARC. My original problem was that I've got EXC_BAD_ACCESS (in objc_retain call) crash in one of my singleton object's + (SingletonClass)shared { ... dispatch_once(..., ^{}); ... } method exactly one line before the dispatch_once call. Based on loggings, and breakpoints my code have not run into the dispatch_once call's block. I didn't know the reason, so I've just commented out the dispatch_once call. My app haven't crashed without that call. After that I've tried to put dispatch_once in a method that my app

ARC on older versions of iOS and OS X

两盒软妹~` 提交于 2019-12-05 20:29:38
This is to clear up some doubt in my conceptual understanding of ARC . If ARC is a compile time technology why isnt it available on all versions of iOS and OS X ? ARC isn't just a compile-time technology. It also relies on some runtime components. There's two parts to this: The reference counting. At compile-time, ARC introduces calls to a bunch of helper functions. These are all documented online , but the important ones are objc_retain() , objc_release() , and objc_autorelease() . These do the same things as calling -retain , -release , or -autorelease on the object, but there's some extra

ARC - why do object pointers require explicit ownership type in function definitions?

断了今生、忘了曾经 提交于 2019-12-05 19:03:51
void testFunction (id testArgument[]) { return; } I'm getting the error "Must explicitly describe intended ownership of an object array parameter". Why does ARC need me to specify the ownership type of the objects in the testArgument array? To expand on Jeremy's answer, ARC had two primary goals when designed: make memory management as fully automatic as possible in pure Objective-C code while also preserving or maximizing efficiency (in fact, ARC can be more efficient than manual retain release). require exactly specific declaration of memory management intent when crossing the boundary

__weak and autorelease pool in ARC in Xcode 4.2

与世无争的帅哥 提交于 2019-12-05 18:39:24
My project use ARC. I tested with the code below: NSString __weak *string; @autoreleasepool { string = [NSString stringWithString:@"AAA"]; } NSLog(@"string: %@", string); I think it output as: string: (null) but it actually output: string: AAA I don't understand it. What is the effect of __weak? EDIT: And this code below: NSString __weak *string; NSString __strong *str; @autoreleasepool { str = [NSString stringWithFormat:@"%@", @"AAA" ]; string = str; } NSLog(@"string: %@", string); It also output as: string: AAA NSString __weak *string; @autoreleasepool { string = [NSString stringWithFormat:@

ARC: How to release static variable?

ぐ巨炮叔叔 提交于 2019-12-05 17:28:35
问题 Will dealloc (below) release the NSString pointed to by the static variable exampleString ? // ExampleClass.h @interface ExampleClass : NSObject @end // ExampleClass.m static NSString *exampleString; @implementation ExampleClass - (void)dealloc { exampleString = nil; } - (id)init { self = [super init]; if (self) { exampleString = [NSString stringWithFormat:@"example %@", @"format"]; } return self; } @end 回答1: Yes, because since you did not specify an ownership qualifier, the LLVM compiler

Delphi TThread under ARC (iOS) not being released

前提是你 提交于 2019-12-05 13:13:45
问题 What is a proper way to terminate a thread using Delphi for iOS under ARC management? Take this simple example: TMyThread = class(TThread) protected procedure Execute; override; public destructor Destroy; override; end; TForm2 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private FThread: TMyThread; public end; { TMyThread } destructor TMyThread