automatic-ref-counting

prevent retain cycle in Swift function pointers

﹥>﹥吖頭↗ 提交于 2019-12-24 03:55:11
问题 How do I prevent a retain cycle when passing around functions as objects in Swift Imagine you have a datasource object like this import UIKit class MagicDataSource:NSObject,UITableViewDatasource { deinit { println("bye mds") } //cant use unowned or weak here var decorator:((cell:CustomCell)->Void)? func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath)->UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier(Identifier, forIndexPath: indexPath) as

Hooking end of ARC dealloc

你离开我真会死。 提交于 2019-12-24 03:08:01
问题 Given the following simple implementation: @implementation RTUDeallocLogger -(void)dealloc { NSLog(@"deallocated"); } @end we run the following code under ARC: @implementation RTURunner { NSArray* arr; } -(void)run{ arr = [NSArray arrayWithObjects:[[RTUDeallocLogger alloc]init], [[RTUDeallocLogger alloc]init], [[RTUDeallocLogger alloc]init], nil]; NSLog(@"nulling arr"); arr = NULL; NSLog(@"finished nulling"); } @end we get the following log output: nulling arr finished nulling deallocated

Release a NSMutableArray when using ARC

对着背影说爱祢 提交于 2019-12-24 02:05:22
问题 I'm developing an iOS application using latest SDK and ARC. I have this variable: NSMutableArray* _previewImageBuffer; And this method: - (void)shutdown { [self stop]; _previewImageBuffer = nil; } Is _previewImageBuffer = nil; correct? If I do it, what happens with memory allocated in _previewImageBuffer`? Is this a memory leak? I want to release this object because I need to release the memory used by it. 回答1: What you're doing is exactly right. Nilifying an object instance variable under

Setting WEAK to a non @property variable

末鹿安然 提交于 2019-12-24 00:48:27
问题 Will need someone with knowledge of ARC to help me. Basically, I have declared some variables as such in my class @interface Class{ NSString* one; NSString* two; } @property(nonatomic,weak) NSString* one; As you can see, I can set the weak identifier to NSString* one . However, I do not need a getter/setter/synthesizer for NSString* two as it is just a common variable. How can I set a weak label to it so the memory is deallocated? Or is automatically set? 回答1: You can do it like this: __weak

Drawing Waveform with AVAssetReader and with ARC

落花浮王杯 提交于 2019-12-24 00:17:18
问题 I'm trying to apply Unsynchronized's answer (Drawing waveform with AVAssetReader) while using ARC. There were only a few modifications required, mostly release statements. Many thanks for a great answer! I'm using Xcode 4.2 targeting iOS5 device. But I'm getting stuck on one statement at the end while trying to invoke the whole thing. Method shown here: -(void) importMediaItem { MPMediaItem* item = [self mediaItem]; waveFormImage = [[UIImage alloc ] initWithMPMediaItem:item completionBlock:^

How can I add -fobjc-arc for a lot files one time

感情迁移 提交于 2019-12-23 21:41:00
问题 I want to add xmppframework to my project, how can I add -fobjc-arc to all xmpp files one time? 回答1: This isn't perfect, but is usually good enough: Select the project at the top left of the project window. Select the target. Open the build phases pane. Select "Compile Sources" Type in "xmpp" into the filter area Select the files you want. Hit Enter and then type -fobjc_arc in the dialog. 回答2: Simple, in your compiler sources select the first item that requires the flag, scroll down and click

Memory Leak iOS (UIImageView,UIImage,CGImage) not freed on ARC

北战南征 提交于 2019-12-23 21:03:56
问题 Im trying to implement a simple video stream but for some reason my memory won't get freed: (void)updateImage:(UIImage *)image{ self.indicator.hidden = TRUE; //CGImageRelease([self.imageView.image CGImage]); self.imageView.image = nil; self.imageView.image = image; [self.imageView setNeedsDisplay]; } If I use CGImageRelease([self.imageView.image CGImage]); memory will be freed. But when I return to a previous view controller the app will crash as it tries to free the allocated memory for that

Does dequeueReusableCellWithIdentifier work with ARC?

不打扰是莪最后的温柔 提交于 2019-12-23 17:27:56
问题 In iOS5, using ARC and prototype cells for tableView on storyboard, can I replace the code below: static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // Configure the cell... return cell; With this simple code?: UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

Objective-C - weak object is registered in autoreleasepool automatically?

自闭症网瘾萝莉.ら 提交于 2019-12-23 17:22:33
问题 I am reading Pro Multithreading and Memory Management for iOS and OS X with ARC, Grand Central Dispatch, and Blocks written by Kazuki Sakamoto. The book wrote: When a variable with a __weak qualifier is used, the object is always registered in autoreleasepool. id __weak obj1 = obj0; NSLog(@"class=%@", [obj1 class]); The above source code is equivalent to: id __weak obj1 = obj0; id __autoreleasing tmp = obj1; NSLog(@"class=%@", [tmp class]); Why does the object need to be registered in

Transitioning to ARC causing delegate issues

非 Y 不嫁゛ 提交于 2019-12-23 17:07:42
问题 After transitioning a project to ARC, I've been having some issues with delegate methods not being called/being called on deallocated instances. I've realized that the problem is that I have a variable that gets allocated and then executes an asynchronous task. For a simple example, assume that there is an object called MyService that responds to a delegate method, executeDidSucceed: - (void)fireRequest { MyService *service = [[MyService alloc] initWithDelegate:self]; [service execute]; } The