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

Is it possible to have an object with retain count -1?

I was refining my project about memory management. I have logged all my retain count at dealloc method, and i faced it. Is it possible? 2013-11-07 11:56:03.974 Project[2749:16403] unitId : -1 2013-11-07 11:56:04.231 Project[2749:16403] specId :…
erdemgc
  • 1,701
  • 3
  • 23
  • 43
0
votes
1 answer

CABasicAnimation memory management

I'm implementing an application in which I use some 'CABasicAnimation'. For example : myAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; myAnimation.fromValue = [NSNumber numberWithFloat:-5.0f]; myAnimation.toValue =…
0
votes
1 answer

retain cycle inside of block with local scope ivars

For the life of me, I cannot figure out what's going on here. As an overview, I have an application that I've created a custom navigation bar, a custom containment view controller, and callbacks to tell me when expensive processes have been finished…
0
votes
1 answer

Objective-C >> Is There a Way to Look at an Object Retain Count Table "on the Run"?

While using ARC, life is much easier in terms of memory management; but, let's say I wish to look at a certain object while the app is running and see how many pointers are pointing to it at each certain point in the code. Is there a way to do that?
0
votes
2 answers

ARC & Memory managment in my app

EDIT I found out that my screens don't get nil because they keep RefCt but my question is why isn't the RefCt 0? I simply create, add and remove the view. Also added a screendump of instruments: So you see at the beginning Malloc 1 initwithframe,…
0
votes
5 answers

Can I send release to an ivar without alloc/init?

I have an NSString property: .h file @property (nonatomic, retain) NSString *str; .m file @synthesize str; What is the retain count of str without alloc/init? Can I [str release] in a method?
0
votes
1 answer

Objective-C retain count on assigning object to new pointer

Disclaimer: I'm pretty new to Objective-C I'm in a command-line project ARC is NOT enabled I have a class called MyClass @interface MyClass : NSObject @end @implementation MyClass @end and my main looks like int main(int argc, char *argv[]) { …
NarbehM
  • 345
  • 2
  • 13
0
votes
2 answers

Retaincount abnormal behaviour while pushing a Viewcontroller

-(void)NewButton { ApplianceViewController *VC = [[ApplianceViewController alloc] initWithNibName:@"ApplianceViewController" bundle:[NSBundle mainBundle]] ; NSLog(@"Retain count before…
0
votes
1 answer

NSObject retainCount not showing the proper value

I am having the property as follows @property(strong,nonatomic)NSArray *dataArray; I am trying to display the retainCount as follows - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the…
Raj
  • 1,119
  • 1
  • 15
  • 32
0
votes
2 answers

Should I retain NSString when it points to a literal?

if (url_leng) { NSString *open_string; if (g_system_status.language_code == 0) open_string = @"Open"; else if (g_system_status.language_code == 1) open_string = @"Abrir"; …
Stanley
  • 4,446
  • 7
  • 30
  • 48
0
votes
1 answer

What is IOS retain do at backend

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 does at backend. Also I like to…
Dilip Rajkumar
  • 7,006
  • 6
  • 60
  • 76
0
votes
1 answer

cocos2d 2.x scene retainCount

I'm pushing a scene to the game I'm working on, after pressing a button in the main menu. This scene is a gameplayScene which should have two layers ad childs: boardLayer and hudLayer. for now I'm testing with the boardLayer, I'm using block to call…
Shefy Gur-ary
  • 628
  • 8
  • 19
0
votes
1 answer

Retain / Release mistake

I am trying to figure out why I am getting EXC_BAD_ACESS by this code. I have no clu. Can anyone help me pls. - (void)loadJsonFile:(NSString*)fileName {    NSError *error = nil;    NSData *jsonData = [[[NSString alloc]                        …
i-developer
  • 441
  • 4
  • 12
0
votes
1 answer

How to print the retain count of an object?

I am trying to print out the retain count of an object in the terminal using NSLog. Here is my code: NSNumber *myInt=[[NSNumber alloc] initWithInteger: 100]; NSLog(@"myInt retain count=%d",[myInt retainCount]); The result should be 1 but what I…
God_of_Thunder
  • 753
  • 3
  • 20
  • 46
0
votes
1 answer

Addsubview and dealloc for memory leaks (retainCount)

I am check the retainCount for the subview after add to the view. the code is : - (void) loadView{ //... toolbar = [[UIToolbar alloc] initWithFrame:nil]; [[self view] addSubView:toolbar]; } - (void) dealloc{ NSLog(@"count=%d",…
Golden
  • 139
  • 1
  • 1
  • 12
1 2 3
11
12