automatic-ref-counting

iOS 5 blocks crash only with Release Build

[亡魂溺海] 提交于 2019-12-31 03:52:08
问题 I have using blocks and ARC, and found in some situation, iOS only crash in Release build. It was wrong way to write code, like this. -(IBAction)clickedButtonA:(UIBarButtonItem*)sender event:(UIEvent*)event { NSMutableArray *arrRows = [NSMutableArray arrayWithCapacity:0]; #warning this code only crash on Release Build.... Don't use this NSMutableDictionary * dicRow = [NSMutableDictionary dictionaryWithCapacity:0]; [arrRows addObject:dicRow]; dispatch_block_t block = ^{ NSString *str =

Lack of autorelease optimization under ARC compiler

久未见 提交于 2019-12-31 03:49:11
问题 I was just wondering, why is there no autorelease pool optimization under the ARC compiler, where it would retain an object in the innermost scope, remove it from the autorelease pool and release once the object is no longer in use? To quote a very impractical example from another question, for(NSUInteger i = 0; i < 10000; i++) { for(NSUInteger j = 0; j < 10000; j++) { NSNumber* n = [NSNumber numberWithUnsignedInteger:j]; //NSLog(@"%@", n); //Disabled this to increase memory bloat faster. } }

Swift: CGPathRelease and ARC

安稳与你 提交于 2019-12-30 18:26:13
问题 Just updated to Xcode Beta 4, and noticed the following compiler error with my code below: var path = CGPathCreateMutable() ... CGPathRelease(path) 'CGPathRelease' is unavailable: Core Foundation objects are automatically memory managed So do I simply just remove my release calls and everything should be fine? Or is there something more I'm missing? And are there any special cases I should be aware of with ARC? 回答1: The Working with Cocoa Data Types section of Using Swift with Cocoa and

Dangling pointers in objective c - does nil also release memory?

爷,独闯天下 提交于 2019-12-30 08:25:13
问题 What I understand is: Memory leaks occur when memory has not been freed or "released" Dangling pointers occur when the pointer is NOT set to nil AND the object is released. my question is: Can setting the object to nil free the memory and clear the pointer reference? i.e. Car *myCar = [[Car alloc] initWithCoolRims: YES]; myCar = nil; //no mem leaks or dang pointers or does the ARC do this: Car *myCar = [[Car alloc] initWithCoolRims: YES]; [myCar release]; myCar = nil; //no mem leaks or dang

ARC: “Pointer to non-const type 'id' with no explicit ownership”

血红的双手。 提交于 2019-12-30 05:44:27
问题 i am upgrading an iOS 4 project to use it with ARC with the sdk5. So i want to use the automatic refactor method for converting the code to use ARC. Unfortunately it does´t work. I get a lots of errors.. for(id* child in childObjectArray){ [child removeParentGroupReferences]; } That gives me the following error output: Pointer to non-const type 'id' with no explicit ownership Any help about that? What do i have to change? Thanks for any help.. 回答1: Change id* to id . id is already defined as

Assignment to ivar in a Block via weak pointer

断了今生、忘了曾经 提交于 2019-12-30 03:20:09
问题 I have a read-only property isFinished in my interface file: typedef void (^MyFinishedBlock)(BOOL success, NSError *e); @interface TMSyncBase : NSObject { BOOL isFinished_; } @property (nonatomic, readonly) BOOL isFinished; and I want to set it to YES in a block at some point later, without creating a retain cycle to self : - (void)doSomethingWithFinishedBlock:(MyFinishedBlock)theFinishedBlock { __weak MyClass *weakSelf = self; MyFinishedBlock finishedBlockWrapper = ^(BOOL success, NSError *e

Enabling in ARC in xamarin

只谈情不闲聊 提交于 2019-12-29 08:47:07
问题 Most of the security and penetration tools report if the ARC is not enabled. fobjc-arc flag is not Found As far as I know we can't do this in xamarin because we don't have build settings here. This flag can be set in build settings only. Even if we could , it won't work because xamarin uses C# and MRC to manage memory by itself. Can anybody explain me how it can be done or not done or my understanding is wrong Edit: We can turn on ARC to a full project by build settings CLANG_ENABLE_OBJC_ARC

Is NSNotificationCenter removeObserver in ARC needed? [duplicate]

独自空忆成欢 提交于 2019-12-29 03:17:06
问题 This question already has answers here : KVO and ARC how to removeObserver (3 answers) In ARC do we need to send removeObserver: explicitly? (4 answers) Closed 6 years ago . Does adding an observer increase the retain count of an object? If yes, does ARC handle the removing of this observer too? If not, where should I remove the observer? 回答1: You should explicitly remove the observer even you use ARC . Create a dealloc method and remove there.. -(void)dealloc { [[NSNotificationCenter

Pragma to explicitly enable ARC?

醉酒当歌 提交于 2019-12-28 15:31:12
问题 Is there a #pragma (or otherwise some construct) to explicitly enable automatic reference counting (ARC) in an Objective-C (or Objective-C++) source file? Even better if the source file can cause compilation to fail if ARC is not enabled. I'm starting to have a number of ARC-only source files that can be potentially shared with other projects. Most of these contain category methods to extend built-in classes. I just don't want to accidentally include these in a non-ARC project and starts

How to deploy to Snow Leopard with ARC enabled

对着背影说爱祢 提交于 2019-12-28 13:52:46
问题 I have an OSX app that I would like to migrate to ARC. Everything works fine if I set the base SDK to 10.7. But when I set it to 10.6 it does not work ( because it does not find _objc_release etc.). So how do I deploy my app to 10.6 with ARC enabled? 回答1: You set the SDK to 10.7 but the Deployment Target to 10.6. Keep in mind: While it's possible to build programs using ARC that run on Mac OS X 10.6 and iOS 4, zeroing weak references are not available on those OSes. All weak references must