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
2
votes
1 answer

Clarification Needed Regarding retainCount

Possible Duplicate: NSString retainCount is 2147483647 Let say i have an class named as MyTestClass.h. There are three NSString variables which are initialized different ways Class structure is look like @interface MyTestClass : NSObject { …
Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
2
votes
3 answers

Objective c - call method on dealloc delegate

I have an object Person and a protocol PersonDelegate Person has a @property (assign) id delegate; somewhere in my code I do: Person *newPerson = [[Person alloc] init]; newPerson.delegate = theDelegate; ... [theDelegate…
Eyal
  • 10,777
  • 18
  • 78
  • 130
2
votes
2 answers

Objective c - NSDictionary retaining objects issue

I'll try to explain myself, I have an object Person and a singleton object PeopleManager that has a NSDictionary *_people. _people is a dictionary that holds Person objects with the personId as key. When a person is created I add it (self) to the…
Eyal
  • 10,777
  • 18
  • 78
  • 130
1
vote
2 answers

How does performSelector:withObject:afterDelay: work?

I have found that after calling [self performSelector:@selector(method1:) withObject:self.tableView afterDelay:3]; that self.tableView's retainCount changes? Why? Thank you very much!
xiaxiulong
  • 41
  • 3
1
vote
1 answer

copy, retain and reference count in NSString

What does actually mean when I use copy, retain with NSString properties and assign it to local variables? @interface SomeClass : NSObject { NSString *name; NSString *name2; } @property (nonatomic, retain) NSString* name1; @property…
Tinku
  • 133
  • 2
  • 15
1
vote
0 answers

"dealloc" of UIView isn't called

I have simple View controller [.h] @interface GLViewController : UIViewController { MGSplitViewController* splitController; } -(void)setSplitter: (MGSplitViewController*)splitter; @end [.mm] -…
Tutankhamen
  • 3,532
  • 1
  • 30
  • 38
1
vote
1 answer

Dismiss modal view cause CALayer retainCount sent to deallocated

In my app, I use method [self DismissModalView...] to dismiss a search view, everything was ok in iOS 3 and iOS 4, but now I upgraded to XCode 4.2 and SDK 5, this method runs ok againts iOS 5 but when I test it against iOS 3 + 4, the application…
Son Nguyen
  • 3,481
  • 4
  • 33
  • 47
1
vote
2 answers

Memory management while copying objects

I know that my question has already been discussed on StackOverflow but i found the answer not complete for my needs. So the question is: NSMutableArray *firstArray = [[NSMutableArray alloc] initWithObjects: obj1,obj2,nil]; NSMutableArray…
Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
1
vote
1 answer

Button getting EXC_BAD_ACCESS by method with ivars

I'm neophyte in obj-c, so I cant understand some of this logic. I want to understand my code and app logic. My app is modification of easy example with animation of UIImageView: this's .h (in standart view-based template) #import…
stworks
  • 79
  • 2
  • 5
1
vote
1 answer

NSTimer retain count increases, why?

I have a problem regarding NSTimer. See the following code: NSTimeInterval timeInterval = 1.0f; SEL selector = @selector(executeDataRefresh); NSMethodSignature *methodSignature = [[ExecuteDataRefesh class]…
user521048
  • 79
  • 1
  • 6
1
vote
1 answer

check retain count

I am doing this : UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mainback.jpg"]]; [self.view addSubview:backgroundImage]; NSLog(@" retain count1 : %d " , [backgroundImage retainCount]); [self.view…
iUser
  • 1,075
  • 3
  • 20
  • 49
1
vote
2 answers

Issue with NSMutableArray visibility / retain

Alright so I am a little new to the NSMutableArray class and I think I am missing something obvious. I have an object pass a NSMutable Array to my window controller like so in my.m: summaryWindow = [[SummaryWindowController alloc]…
acidprime
  • 279
  • 3
  • 18
1
vote
2 answers

NSMutableArray getting released?

I have a NSMutableArray whose property is (nonatomic, retain), and it's getting released for some reason, here's the code when I assign it (tableData is the NSMutableArray): tableData = [[[NSMutableArray alloc] init] autorelease]; When I alloc it,…
user635064
  • 6,219
  • 12
  • 54
  • 100
1
vote
2 answers

Cross retain trouble

How do you get around the cross retain situation when two objects retain each other? consider this class structure: Container.h @interface Container : NSObject { NSObject *child; } @property (nonatomic, retain) NSObject…
Edward Ashak
  • 2,411
  • 2
  • 23
  • 38
1
vote
3 answers

Objective-C Retain Count goes from 0 to 2

I'm new to Objective-C. This is my first post here. I created a singleton for the purpose of managing my applications interface to a database. To start out simple, I have used an NSMutableArray as an ivar. As you will see in the code below and the…
Jim
  • 5,940
  • 9
  • 44
  • 91