automatic-ref-counting

iOS: How to remove object from memory with ARC enabled?

爷,独闯天下 提交于 2019-11-27 21:50:20
问题 I am developing an iOS app with the iOS 5 SDK, Automatic Reference Counting is enabled. But I have a specific object that is being created in large numbers and must be released after a second because otherwise the device will become very slow. It looks like they are not released, as the device is very slow. Is there a way to manually release an object when ARC is enabled? EDIT: My code, this is called 200 times a second to generate sparkles. They fade out after 0.8 seconds so they are useless

assign properties, ARC and Core Foundation objects

人走茶凉 提交于 2019-11-27 20:56:28
Edit 2. Thanks to Ken this is now working. And I even think I understand why :-) Here's the amended line: - (void) reCreatePath { CGMutablePathRef p = ::CGPathCreateMutable() ; ::CGPathMoveToPoint (p, 0, TL.x, TL.y) ; // [snip] ::CGPathAddLineToPoint (p, 0, BL.x, BL.y) ; ::CGPathCloseSubpath(p) ; self.path = p ; ::CGPathRelease(p) ; // <<== THIS IS IT!! :-) } Edit. I still don't get it. I tried Chuck suggestion: @property (nonatomic, strong) __attribute__((NSObject)) CGPathRef path ; Like so: @interface TopLeftSlidingView () @property (nonatomic, strong) __attribute__((NSObject)) CGPathRef

Xcode ARC (automatic reference counting), “release is unavailable”

久未见 提交于 2019-11-27 20:53:08
For my first time using Xcode I was following a tutorial online. I did everything as the tutorial showed me, but I am afraid that it's too outdated. The error I encounter is: [font_attributes release]; 'release' is unavailable: not available in automatic reference counting mode ARC forbids explicit message send of 'release' My knowledge on Cocoa and Xcode is limited, but I still wish to expand my learning. How may I fix the ARC issue? NJones You have two options: 1) Turn off ARC for this project. This is done by setting 'Objective-C Automatic Reference Counting' to NO in the ' Build Settings '

Weak property is set to nil in dealloc but property's ivar is not nil

徘徊边缘 提交于 2019-11-27 20:16:17
I noticed the following in Objective-C with ARC enabled: Let's have simple class A and autosynthesized weak property @interface A @property (nonatomic, weak) id refObject; @end @implementation A @end And second class B with dealloc implemented @interface B @end @implementation B -(void) dealloc { NSLog(@"In dealloc"); } @end And finally somewhere in class A have the following: @implementation A ... -(void) foo { B* b = [B new]; self.refObject = b; // Just use b after the weak assignment // in order to not dealloc 'b' before assignement NSLog(@"%@", b); } ... @end If I set a breakpoint in [B

Lazy initialisation and retain cycle

一个人想着一个人 提交于 2019-11-27 20:07:46
While using lazy initialisers, is there a chance of having retain cycles? In a blog post and many other places [unowned self] is seen class Person { var name: String lazy var personalizedGreeting: String = { [unowned self] in return "Hello, \(self.name)!" }() init(name: String) { self.name = name } } I tried this class Person { var name: String lazy var personalizedGreeting: String = { //[unowned self] in return "Hello, \(self.name)!" }() init(name: String) { print("person init") self.name = name } deinit { print("person deinit") } } Used it like this //... let person = Person(name: "name")

Recommended way to declare delegate properties with ARC

梦想的初衷 提交于 2019-11-27 20:03:25
I used to declare all delegate properties as @property (assign) id<FooDelegate> delegate; I was under the impression that all assign properties should now be weak pointers, is this correct? If I try to declare as: @property (weak) id<FooDelegate> delegate; I get an error while trying to @synthesize (autogenerated weak properties are not supported). What's the best practice in this case? Jano Use __unsafe_unretained instead weak for ARC projects targeting iOS 4 and 5. The only difference is that weak nils the pointer when deallocated, and it's only supported in iOS 5. Your other question is

Weak Reference to NSTimer Target To Prevent Retain Cycle

怎甘沉沦 提交于 2019-11-27 19:52:24
问题 I'm using an NSTimer like this: timer = [NSTimer scheduledTimerWithTimeInterval:30.0f target:self selector:@selector(tick) userInfo:nil repeats:YES]; Of course, NSTimer retains the target which creates a retain cycle. Furthermore, self isn't a UIViewController so I don't have anything like viewDidUnload where I can invalidate the timer to break the cycle. So I'm wondering if I could use a weak reference instead: __weak id weakSelf = self; timer = [NSTimer scheduledTimerWithTimeInterval:30.0f

release method deprecated

半世苍凉 提交于 2019-11-27 19:32:30
问题 When has happen to the release method? I always release a memory allocation when I am done with it and now it seems that the method has been deprecated. Or maybe it does not work for some objects? Anyway, this is what I did: Customer *aCustomer = [[Customer alloc] init]; ... [aCustomer release]; and I get an error there... Anyone care to explain why I get an error now that I release my memory? The error message is: 'release' in unavailable: not available in automatic reference counting mode

ARC forbids explicit message send of 'retain' issue

僤鯓⒐⒋嵵緔 提交于 2019-11-27 19:31:16
I'm using this very simple code from the Apple Guide: NSMutableData *receivedData; // Create the request. NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // create the connection with the request // and start loading the data NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if (theConnection) { // Create the NSMutableData to hold the received data. // receivedData is an instance variable declared elsewhere. receivedData = [

'__strong' only applies to objective-c object or block pointer types; type here is XXX" warning

大憨熊 提交于 2019-11-27 19:29:56
问题 i get many warnings of type: '__strong' only applies to objective-c object or block pointer types; type here is... the warnings are pointing to framework headers. e.g NSNotification, NSURL, NSIndexset etc.. what are they and how can i repair it? note 1: i use ARC note 2: the app seems to work edit 1: the warnings seems to originate from my pch file. which is: // // Prefix header for all source files of the 'myapp' target in the 'myapp' project // #import <Availability.h> #ifndef __IPHONE_5_0