automatic-ref-counting

Collections of zeroing weak references under ARC

不问归期 提交于 2019-11-29 20:52:41
How can I get an array of zeroing weak references under ARC? I don't want the array to retain the objects. And I'd like the array elements either to remove themselves when they're deallocated, or set those entries to nil. Similarly, how can I do that with a dictionary? I don't want the dictionary to retain the values. And again, I'd like the dictionary elements either to remove themselves when the values are deallocated, or set the values to nil. (I need to retain the keys, which are the unique identifiers, at least until the corresponding values are deallocated.) These two questions cover

ARC, ivars in Blocks and Reference Cycles via Captured Self

五迷三道 提交于 2019-11-29 20:27:30
I’m working in a pure iOS5/ARC environment, so I can use __weak references as needed. I do reference ivars in a block in many situations, most notably, animation blocks that move views around, which are properties of say, my view controller class. My question: In the most trivial use of ivars in a block, am I creating a reference cycle? Do I need to use the __weak self / strong self technique everytime I write a block that manipulates instance variables of the containing object? I’ve been re-watching the 2011 WWDC Session #322 (Objective-C Advancements in Depth) to understand the nuances

Understanding retain cycle in depth

做~自己de王妃 提交于 2019-11-29 20:20:16
Lets say we have three objects: a grandparent, parent and child. The grandparent retains the parent, the parent retains the child and the child retains the parent. The grandparent releases the parent. What will happen in this case ? Unless there is some other reference to the parent or child, they both become orphaned. But the retain cycle between the parent and child prevent either from being released and they become wasted memory. A child should never retain a parent. If anything, use a weak reference in the child to maintain a reference to the parent. Retain Cycle is the condition When 2

Property 'x' not found on object of type 'y *' error only with ARC

早过忘川 提交于 2019-11-29 18:07:25
This error very strange. I have a bunch of properties in app delegate which I have no problem to access. My code worked fine without ARC, but when I turned on ARC I receive this very strange error. Property 'navigationController' not found on object of type 'AppDelegate *' A bunch of other properties work just fine except this. I already clean everything and restarted Xcode. Here is the code: AppDelegate.h: @interface AppDelegate : UIResponder <UINavigationControllerDelegate> { UINavigationController *navigationController; NSString *appName; } @property (strong, nonatomic) NSString *appName;

BWDB SQLite wrapper for iOS ARC issues

拥有回忆 提交于 2019-11-29 17:40:03
I am trying to use Bill Weinman's BWDB wrapper, which can be downloaded here: http://bw.org/iosdata/ I can't convert it to ARC properly, can someone more experienced then i to look at it? Main issue is va_list in insertRow & updateRow methods, idk what to do with it. The rest of the errors are easy to get rid of. Thanks in advance for any help/advice! Header file // BWDB.h // Created by Bill Weinman on 2010-09-25. // Copyright 2010 The BearHeart Group, LLC. All rights reserved. #import <Foundation/Foundation.h> #import <sqlite3.h> #define defaultDatabaseFileName @"bwtest.db" #define BWDB

Memory leak in NSString stringWithUTF8String: with ARC enabled

佐手、 提交于 2019-11-29 17:25:01
In my application i have enabled the ARC. But in my application following lines gives me memory leaks according to instruments. It is in ios 7.0. -(id)init{ variables = [[NSMutableArray alloc] init]; // Leak events = [[NSMutableArray alloc] init]; //Leak return self; } Update But in my app if i do something like below it does not show me any leak. But i can't add items in to the variables. -(id)init{ variables = [[[NSMutableArray alloc] init] copy]; // No Leak events = [[[NSMutableArray alloc] init] copy]; //No Leak return self; } -- NSString *utfString =[NSString stringWithUTF8String:(const

Weak property not zeroing using ARC

血红的双手。 提交于 2019-11-29 15:53:16
I have the following simple code for an object that holds a weak reference: // interface @interface GMWeakRefObj : NSObject @property (weak) id object; @end // implementation @implementation GMWeakRefObj @synthesize object; @end When I run the following test code it fails on the second assert: NSData* d = [[NSData alloc] init]; GMWeakRefObj* weakRef = [[GMWeakRefObj alloc] init]; weakRef.object = d; NSAssert(weakRef.object != nil, @"Reference wasn't assigned"); d = nil; NSAssert(weakRef.object == nil, @"Reference wasn't zeroed"); // <-- FAIL Aren't ARC weak references supposed to be zeroing?

Enabling in ARC in xamarin

谁说胖子不能爱 提交于 2019-11-29 14:38:58
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=YES But there is no way to do this in xam studio ... setting the value in mtouch also throws error Add

ARC weak ivar released before being returned - when building for release, not debug

别说谁变了你拦得住时间么 提交于 2019-11-29 14:31:07
I have a class that creates an object lazily and stores it as a weak property. Other classes may request this object, but must obviously keep a strong reference to it to keep the object from being deallocated: // .h @interface ObjectManager @property(nonatomic, weak, readonly) NSObject *theObject; @end // .m @interface ObjectManager () @property(nonatomic, weak, readwrite) NSObject *theObject; @end @implementation ObjectManager - (NSObject *)theObject { if (!_theObject) { _theObject = [[NSObject alloc] init]; // Perform further setup of _theObject... } return _theObject; } @end When the scheme

How can I get OCMock under ARC to stop nilling an NSProxy subclass set using a weak property?

馋奶兔 提交于 2019-11-29 14:09:07
问题 Under ARC , I have an object, Child that has a weak property, parent . I'm trying to write some tests for Child , and I'm mocking its parent property using OCMock . Under ARC, setting an NSProxy subclass using a synthesized weak property setter doesn't set the property ... the line after the weak property is set, checking it reveals that it's already nil . Here's the concrete example: @interface Child : NSObject @property (nonatomic, weak) id <ParentInterface>parent; @end @implementation