Tag: 自动ref counting

三angular形当你不合成时会发生什么

在启用了iOS ARC的项目中,当我不合成属性时会发生什么,因为保留/释放是不允许的? @interface SomeClass : NSObject { NSMutableArray* _pieces; } @end 在这种情况下,iVar_pieces的内存语义是什么? 说我使用它, _pieces = whatever 。 当我的SomeClass的实例被释放时,_pieces是否设置为零? 是否将_pieces存储为弱引用? 如果所有其他保留了_pieces的对象都释放它,当我尝试访问它时它会为空吗?

游戏中心authentication的Xcode 4.6 ARC警告

这是一个新的编译器警告,只有当我将XCode更新到4.6时才显示出来。 我的代码直接从苹果的文档(这是我的iOS 6代码btw)中解除。 GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) { [self setLastError:error]; if(localPlayer.authenticated){ 警告 – 在此块中强烈捕获“localPlayer”可能会导致保留周期

应用程序转换为ARC,现在得到关于我的属性的警告

我只是将我的应用程序转换为ARC ,而且它的构build正常,我得到了600条警告,都与我的属性有关。 如: 默认属性“assign”不适合非gc对象 未指定“分配”,“保留”或“复制”属性 – 假定为“分配” Xcode转换我的代码后,这是我的属性看起来像: @property (nonatomic) EKEventStore *eventStore; @property (nonatomic) EKCalendar *defaultCalendar; @property (nonatomic) UIActionSheet *currentActionSheet; @property (nonatomic) UILabel *noEventLabel; 有人谈到需要strong对所有这些。 这是这种情况吗? Xcode忘了添加一些东西?

阻止recursion并打破保留周期

为了更好地说明这个问题,请考虑以下简化forms的块recursion: __block void (^next)(int) = ^(int index) { if (index == 3) { return; } int i = index; next(++i); }; next(0); XCode(支持ARC)警告说,“ 在这个块中强烈地捕获'下一个'可能会导致一个保留周期 。 同意。 问题1 :通过以下面的方式将块本身设置nil来保留周期是否成功: __block void (^next)(int) = ^(int index) { if (index == 3) { next = nil; // break the retain cycle return; } int i = index; next(++i); […]

UIPopoverController dealloc获取调用ARC环境

在第二次显示popup窗口控制器(解散popup窗口然后重新显示之后)时,出现以下错误: 终止应用程序,由于未捕获的exception'NSGenericException',原因:' – [UIPopoverController dealloc]达到popup仍然可见。 堆栈跟踪只是一堆hex,SIGABRT每次都发生在UIApplicationMain。 这是button触发的代码: – (IBAction)createNewScore:(id)sender { if (self.pc) if (self.pc.popoverVisible) return; else // Breakpoint is hit here—crashes after this line [self.pc presentPopoverFromBarButtonItem:(UIBarButtonItem *)sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; NGDocumentInfoViewController *documentInfoVC = [[NGDocumentInfoViewController alloc] initWithBlankDocumentTargetInManagedObjectContext:self.context]; UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:documentInfoVC]; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneCreatingNewScore:)]; UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel […]

在Xcode 4中将非ARC文件转换为ARC项目

我在ARC项目中使用了一些非ARC代码,即Three20。 我已经添加了所有适当的编译器标志,并且一切正常。 但是,我需要inheritance一些Three20类,并且我不确定是否应该将编译器标志添加到非ARC的新文件中,或者编译器会计算出来,并添加适当的发布调用。 回顾一下: – XCode 4中的ARC项目 – 包含非ARC代码(Three20) – 需要子类化非ARC文件中定义的内容 – 是否需要添加发布调用? – 我需要为子类中的非ARC添加编译器标志吗?

iOS AdMob内存泄露?

我刚开始使用AdMob但是我注意到,运行了大约一个小时之后,它累积了50MB! 让人惊讶。 我想过释放它,但是因为我正在使用ARC所以不能使用它。 有任何想法吗? 我正在使用google提供的入门代码: GADBannerView *bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; CGRect newFrame = CGRectMake(self.scroller.frame.origin.x,self.scroller.frame.origin.y + 70,self.scroller.frame.size.width,self.scroller.frame.size.height); [self.scroller setFrame:newFrame]; bannerView_.adUnitID = @"XXXXX"; bannerView_.rootViewController = self; [bannerView_ setFrame:CGRectMake(0, 20, bannerView_.bounds.size.width, bannerView_.bounds.size.height)]; [self.view addSubview:bannerView_]; [bannerView_ loadRequest:[GADRequest request]];

强/弱的自我打破保持周期

我读过强/弱的self打破保留周期的post,但我仍然困惑,他们如何工作。 我明白使用__weak typeof(self) weakSelf = self来创build一个对自我的弱引用,但是我对强烈的引用感到困惑。 据我所知,强烈的参照是有一个强烈的self参照,以便它不会在块的权利结束之前被释放。 那么为什么有必要有__strong typeof(self) strongSelf = weakSelf ? 这不就结束了指向自己的对象吗? 那么,为什么不strongSelf = self呢?

ld:在iOS 4.3上复制符号_objc_retainedObject,但不在iOS 5.0上

一些背景 – 我使用Diney的指南在http://db-in.com/blog/2011/07/universal-framework-iphone-ios-2-0/上构build了一个自定义框架 它为armv6 / armv7构build,它是一个基于ARC的框架,编译4.3的解构目标。 当我把结果框架在一个5.0项目,它的工作很好,但是当我把它放在一个4.3项目(ARC或非弧,没有关系),我得到以下,我不明白… 我也尝试手动添加libarclite.a,但它并没有改变任何东西。 ld:在/Users/freak4pc/Project/MyFramework.framework/MyFramework和/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a(arclite.o)中复制符号_objc_retainedObject用于架构armv7 Command / Developer /Platforms/iPhoneOS.platform/Developer/usr/bin/clang失败,退出代码1 希望对此有帮助。 谢谢 夏嘉曦

在UIPageViewController中释放未使用的页面

我为基于UIPageViewController的图片书的每个基于UIViewController的页面使用单独的.h , .m和.xib文件。 每个页面加载animation,音乐等,大约需要4MB的内存。 在乐器中,随着每个页面的加载,可用内存下降大约4MB。 这个内存从不被释放,因为页面被转动。 它最终会给出内存警告。 UIPageViewController似乎保持它在内存中实例化的每个页面,并不会卸载它。 所以,当页面变快,应用程序崩溃。 我希望能够卸载除UIPageViewController所需的3个页面之外的所有页面 – 前一页,当前页和下一页。 我怎样才能卸载不受欢迎的页面,因为它们是由UIPageViewController实例化的。 以下是UIPageViewController取出的页面的数组。 所有的页面(Page1,Page2等)基本上只是加载图像文件,提供基本的animation,并有音乐。 //ARRAY OF PAGES pageArray = [[NSArray alloc] initWithObjects: (id)[[Page1 alloc] initWithNibName:nil bundle:nil], [[Page2 alloc] initWithNibName:nil bundle:nil], [[Page3 alloc] initWithNibName:nil bundle:nil], [[Page4 alloc] initWithNibName:nil bundle:nil], [[Page5 alloc] initWithNibName:nil bundle:nil], [[Page6 alloc] initWithNibName:nil bundle:nil], [[Page7 alloc] initWithNibName:nil bundle:nil], [[Page8 alloc] initWithNibName:nil bundle:nil], […]