Questions tagged [retaincount]

-retainCount is a commonly misused method related to memory management of objects in the Cocoa and Cocoa Touch frameworks. It should never be used.

Quoting the NSObject documentation:

This method is of no value in debugging memory management issues. Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method.

To understand the fundamental rules of memory management that you must abide by, read “Memory Management Policy”. To diagnose memory management problems, use a suitable tool:

  • The Clang Static analyzer can typically find memory management problems even before you run your program.
  • The Object Alloc instrument in the Instruments application (see Instruments User Guide) can track object allocation and destruction.
180 questions
0
votes
3 answers

How do I fix a leaked object with a retain count of +1?

I have a leaked object in the following code. How do I fix it? I tried adding a [apiViewController release]; but when I analyze the app I still get a : if (idx == 2) { NSLog(@"you touched menu 2"); APICallsViewController…
hanumanDev
  • 6,592
  • 11
  • 82
  • 146
0
votes
2 answers

Reference count of Managed Objects

I have class A (subclass of NSManagedObject) that has a property of class B (also subclass of NSManagedObject), the property is @synthesize not @dynamic, there is no relationship between A and B in my model, I just want that A will keep a reference…
-1
votes
2 answers

Setting a property to nil when creating it with "assign"

What happens if I create a property with "assign" attribute set the property to nil in dealloc method @property (nonatomic, assign) NSString* myData; - (void)dealloc { self.myData = nil; }
Abhinav
  • 37,684
  • 43
  • 191
  • 309
-1
votes
1 answer

An iPhone design pattern & memory management issue

In my iPad application, I have a single UINavigationController and multiple viewControllers acting as tabs. I'm not using the UITabbarController since I wanted certain custom look for the tabs, so have been loading the different controllers which…
neha
  • 6,327
  • 12
  • 46
  • 78
-1
votes
2 answers

When the class creates an object through the alloc method, does the object's reference count change to 1?

When we call alloc with a Class, Whether the object's reference count will be 1. For example: NSObject *obj = [NSObject alloc];,After this line of code is executed, the reference count of the object is 0 or 1? I read the source code, I can't find…
-1
votes
2 answers

Can an Objective-C object's retain count drop below zero?

I have learned manual memory management in Objective-C and every article said: "When the retain count of an object drops to 0, the dealloc method is called and the object is destroyed". And nothing more. But there is no answer for several questions:…
WantToKnow
  • 1,767
  • 2
  • 12
  • 18
-1
votes
1 answer

NSString Retain Count

Whats the retain count of the NSString in the below mentioned Code snippet? self.a = @"abcd"; // self.a is a NSString with (nonatomic, Strong) Attributes NSLog(@"Retain Count of A == %d",(int)[self.a retainCount]); self.b = self.a;// self.b is…
-1
votes
1 answer

RetainCount is -1 after alloc?

Please don't mark Duplicate:- I have created the few lines NSString *str = [[NSString alloc] init]; str = @"Test"; NSLog(@"%d",[str retainCount]); and Output is -1 .Please explain.
Sanoj Kashyap
  • 5,020
  • 4
  • 49
  • 75
-1
votes
1 answer

Unexpected retainCount

Have a look at this code-snippet with a simple retain/release scenario: #import @interface SomeClass : NSObject @end @implementation SomeClass @end int main(int argc, const char * argv[]) { SomeClass *aClass =…
-1
votes
1 answer

NSString retain count in Objective-C

NSString* nsString=[[NSString alloc]initWithString:@"nsString"]; NSLog(@"nsString RetainCount:%li",[nsString retainCount]); the corresponding result is: 2013-03-04 11:18:03.291 ARC[655:303] nsString RetainCount:-1 in addition: if use init a…
user2130310
  • 13
  • 1
  • 3
-1
votes
1 answer

View object becoming nil abruptly - xcode

I have a View object becoming nil abruptly in my method. I am not using ARC no threading is involved Whats happening is that 1st time i call that 1stmethod method everything works fine and the reference to the livescoreSettings is retained. Next…
Sharanya K M
  • 1,805
  • 4
  • 23
  • 44
-2
votes
2 answers

iOS retain count issue

this is part of my code: NSMutableArray oldWordsArray; newWordsArray= [self getNewWordArray]; -(NSMutableArray *) getOldWordArray{ NSString *user_id = (NSString*)[tool readObkect:@"user_id"]; NSMutableArray oldWords = [[NSMutableArray…
Joe Wu
  • 11
  • 5
-2
votes
2 answers

Multiple questions regarding retain count in objective c

Here is my code. - (void)viewDidLoad{ [super viewDidLoad]; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 240, 280)]; [view setTag:101]; UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10,…
Viral Narshana
  • 1,855
  • 2
  • 21
  • 45
-2
votes
2 answers

please solve here retain count of NSString objects in Objective C

Please solve this. NSString *S1 = @"abc"; //retain count of s1 ?? NSString *S2 = [S1 copy]; //retain count of s2 and s1 ?? NSString *S3 = [S2 copy]; //retain count of s3 and s2 ?? NSString *S4 = [S3 retain]; //retain count of s4 and s3…
Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
-3
votes
2 answers

What are the reference counts of objects A and B after assigning B=A?

What is the reference count of A and B after assigning B=A in this code? Class1 *A=[[Class1 alloc] init]; Class1 *B=[[Class1 alloc] init]; [A retain]; NSMutableArray *tempArray= [NSMutableArray alloc]init]; [tempArray addobject:A]; B=A;
ALOK KUMAR
  • 745
  • 5
  • 7
1 2 3
11
12