retaincount

Using 'self' on RxSwift closures… What about instance methods as param?

白昼怎懂夜的黑 提交于 2019-12-20 03:24:15
问题 In other stack overflow questions, it was emphasized that the capture [weak self] should be used for closures that aren't owned by the class because self could be nil before the closure completes. An alternative when the closure is owned by the class itself is [unowned self] . My question is do I need to use [unowned self] when the function I pass as a parameter is an instance method of the current class? Example import RxSwift class Person { var name = "Default name" class func getPersons()

Why retainCount = 2 - after release?

我的未来我决定 提交于 2019-12-18 07:24:16
问题 I use this code. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. view = [[UIView alloc] init]; [_window addSubview:view]; [view release]; NSLog(@"count - %d", [view retainCount]); [self.window makeKeyAndVisible]; return YES; } - (IBAction)click{ NSLog(@"count - %d", [view retainCount]); } When i click to uibutton - my view retain count = 2. Why is this happening? 回答1:

does addSubview increment retain count?

故事扮演 提交于 2019-12-18 05:01:11
问题 I've tested it and it looks like it does. So my question is, does it ALWAYS increment the retain count. So everytime I do something like this: UIView *theView = [[[UIView alloc] initWithFrame:(CGRect)aFrame] autorelease]; [self.view addSubview:theView]; Am I actually leaking memory? I have a global property @property (nonatomic, retain) UILabel *ingredientsTextLabel; which I instantiate in viewDidLoad with this code: I just have the property named, theres no property for it in my header, so

How do I ensure there is only one instance of a class at any one time in Objective-C?

送分小仙女□ 提交于 2019-12-13 02:33:17
问题 This is slightly different from the standard singleton pattern, in that if all external references to an object have released, then the singleton will be released, too. Then, later, when a new object is requested, a new singleton is created. So, something like this: MyThing *thing1 = [MyThing new]; MyThing *thing2 = [MyThing new]; // thing1 & thing2 are the same object. thing1 = nil; thing2 = nil; thing1 = [MyThing new]; thing2 = [MyThing new]; // thing1 and thing2 are a the same objet, but

Objects' retain counts never go below 1 despite deliberately overreleasing

梦想与她 提交于 2019-12-12 21:16:26
问题 I am checking on the retain count of some objects NSLog(@"r = %d", [aObject retainCount]; It seems that the lowest value I can get is "r = 1", even if I deliberately add extra "release" calls [aObject release]; The "r = 1" limit holds even if I try to put the "release" and "NSLog" test codes in the object's dealloc method. The Cocoa run-time just seems to neglect my extra releases up to "r = 1" before crashing with an "EXC_BAD_ACCESS" at the very end of the sample program (without GC). My

What is IOS retain do at backend [closed]

橙三吉。 提交于 2019-12-12 04:12:56
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Consider I am allocating an object. Please see the below image In the above image *myObject is a pointer. It is referring to an space allocated to that object. When we retain the object, I like to know what it

How to find the Retain count?

大城市里の小女人 提交于 2019-12-12 00:32:17
问题 Please explain me the below code of lines, I am just confused.., Nsstring *a; Nsstring *b; a = [b retain]; what is the retain count of a & b. a = [b copy]; what is the retain count of a & b. Thanks in advance. 回答1: Technically the retain count in the situation you posted is indeterminate, since you never initialize your variables. Calling retain on an uninitialized pointer will probably crash. Second, the retain count in your situation depends on how you init your variables. NSString *a;

Why is KVO retaining all of NSMutableArray's objects?

落花浮王杯 提交于 2019-12-11 15:34:42
问题 I'm having a real pain trying to figure out why KVO is retaining all values that are being observed. Scenario: I have an NSMutableArray with weak references. (Set up with CFArrayCreateMutable and Callback having NULL for both retain and release). Meaning any object added is never retained / released. I have an NSArrayController observing values of the NSMutableArray. But now, every object of the NSMutableArray is also retained. Why is this happening and how do I stop this? 回答1: How do you

iOS about retainCount

微笑、不失礼 提交于 2019-12-11 10:23:22
问题 Now I have a ClassA : NSObject , and then in the viewcontroller viewDidLoad , look at the under code: - (void)viewDidLoad { ClassA *a = [[ClassA alloc] init]; NSLog(@"a retainCount = %d", [a retainCount]); ClassA *b = a; NSLog(@"a retainCount = %d b retainCount= %d ", [a retainCount],[b retainCount]); [a release]; NSLog(@"a retainCount = %d b retainCount= %d", [a retainCount],[b retainCount]); [super viewDidLoad]; } The console output looks like: 2012-11-02 14:43:35.437 RetainCountTest[1043

Why is the retain count of @1 equal to 7, 8 or 10?

微笑、不失礼 提交于 2019-12-11 02:08:23
问题 I created an empty iOS app on Xcode 4.4.1, and did the following: NSNumber *n1 = @1; NSNumber *n2 = @2; NSNumber *n3 = @3; NSNumber *n100 = @100; NSString *s = @"haha"; NSArray *a = @[n1, s]; NSDictionary *d = @{ @"ha" : @1, @3 : @"hello" }; NSLog(@"retain count of @1 is %i", [n1 retainCount]); NSLog(@"retain count of @2 is %i", [n2 retainCount]); NSLog(@"retain count of @3 is %i", [n3 retainCount]); NSLog(@"retain count of @100 is %i", [n100 retainCount]); NSLog(@"retain count of @\"haha\"