retain

iPhone - Retain Count - Retain count goes up for no apparent reason

Hello. Quick question, hopefully I am just missing something simple. Ok I have one class that holds a pointer to another; MainMenuClass and NormalGameClass. Inside of the MainMenuClass I do the following. m_NormalGame = [[NormalGameMode alloc] initWithNibName:@"NormalGameMode" bundle:[NSBundle mainBundle]]; m_NormalGame.delegate = sel...

NSArray objects go out of scope after returning pointer

I am attempting to use the below code in a function to return an array of dictionary objects. Unfortunately, after the return to the next function in the stack all of the rows in the mutable array have become 'out of scope'. From my understanding, the array should retain the row (dictionary) object automatically so even after the retur...

objective-c addSubView retain count

I was under the impression that adding a subview to a view goes like this: UITableViewController *sitesel = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped]; sitesel.view.frame = CGRectMake(0,0,100,100); [self.left addSubview:sitesel.view]; [sitesel release]; But it seems I should not release the sitesel (the cont...

Memory leak with an array - objective c

Hi, am having some trouble with attempting to remove a memory leak from my code. In the code below, I get a memory leak on the line "configurationArray = [[NSArray arrayWithContentsOfFile:controllerConfigurationFilePath] retain];" however when I remove the retain, the application crashes and changing the retain to an autorelease also cau...

How can I get an NSNumber without performing alloc on it, so it will respond to initWithInt?

My understanding is that a 'convenience' method such as [nsnumber initWithInt] should create a copy of the indicated class, initialized to the desired value. minutesLeft=[NSNumber initWithInt:((timeLeft)%60)]; Timeleft is an integer, so initWithInt should be working, and the result should be that minutesLeft (a property set to retain)...

How to properly release assigned object with no handle.

Instruments is pointing out that this is a memory leak, however I'm unsure how to release it properly, or when it should be released. Is there a better convention for assigning properties with new objects that are only needed inside a loop? The specific line is the "expense.addedDate = [NSDate new];". - (void) addObjects:(NSString *)it...

How many times do I release an allocated or retained object?

Hi, I am making an iPhone game. I want to release all the object that have been allocated or retained. In the dealloc function I am releasing all such objects but then realized sometimes i end up releasing objects when they have not been allocated yet. So I figured I need to check if its retainCount is greater than zero or not before i ...

When to use self and when to use retain

Hi, am working my way through the "Beginning iPad Development" Apress book and have noticed that sometimes when the author is assigning values to a property they will use: self.variable = value; and other times, they will use: variable = [value retain]; In both cases variable is a property defined as: @property (nonatomic, retain)...

Objective-C retain clarification

I'm looking at this code: NSMutableArray *controllers = [[NSMutableArray alloc] init]; for (unsigned i = 0; i < kNumberOfPages; i++) { [controllers addObject:[NSNull null]]; } self.viewControllers = controllers; [controllers release]; Later on... - (void)dealloc { [viewControllers release]; ... } I see that self.viewCon...

why does it works fine without 'retain' the object?

Here i used auto-release for 'tempString' in the method 'test'. According to the rule, i should use "[temp retain]" in the main . But i didnt use it. still it works fine and prints the output. Then what is the need of "retain"? Can anyone pls tell me the reason? Thanks in advance. -(NSMutableString *) test : (NSMutableString *) aString...

What are the semantics of using retain vs. copy for a property of type NSMutableSet;

Hello, I have been using the most excellent Accessorizer to auto-magically generate setters/getters for my Obj-C code in Xcode. Recently a change was made in Accessorizer: old version of Accessorizer: @property (nonatomic, retain) NSMutableSet *setA; @property (nonatomic, retain) NSMutableSet *setB; new version of Accessorizer: @pro...

UIView being retained

Hi, I'm having real problems tracking down why my UIView isn't deallocing. I have a UIViewController with several UIViews, all of which are IBOutlet properties that retain. I'm sure to release the UIView in the dealloc method of the UIViewController. However the dealloc of my UIView is never called. I have no idea what else has reta...

Should I use @property (retain) for a @dynamic property setter that is retaining?

I have the following code for a property whose getter/setter I write manually using the @dynamic keyword: @property (nonatomic, retain) NSObject* obj; @dynamic obj; -(NSObject*) obj { return obj; } -(void) setObj:(NSObject*)newObj { [obj release]; obj = [newObj retain]; } My question is, if I remove the retain from the @p...

Does @property (readonly, retain) have a meaning ?

XCode accepts it. But will retain be applied when I internally set the property (no setter outside since readonly but when I initialize the value in a class method) ? Regards, Apple92 ...

How to fix strange retain count (1 init - 3 retaincount)? + edit: dealloc problem

So my code goes like this: ArticleControllerController *ac = [[ArticleControllerController alloc] init]; ac.categoryIndex = idx; NSLog(@"acc retain: %d", [ac retainCount]); [app.nav pushViewController:ac animated:NO]; NSLog(@"acc retain: %d", [ac retainCount]); [ac release]; NSLog(@"acc retain: %d", [ac retainCount]); ...

UIViewController retain problem: count never reaches zero

Please, take a look at my code bellow. This part pops top view controller (usually, the same ArticleControllerController) from the stack (I found that the problem stays the same no matter if I pop single controller or pop to the root controller), creates new one and adds to the stack. The problem is, that its retain count never goes to ...

How to set retain for properties nested to struct ?

Hi, There is really something in objc I cannot understand. I know how to make retainable properties but cannot understand how to make retainable "sub" struc fields which are not "public" properties but only "private" properties (the private properties are only managed by my methods). Here is my code: struct _device_descriptor { ...

How is retain setter implemented with @synthesize?

I have the following in the header: @property (nonatomic, retain) UIView *overlay; And in the implementation: @synthesize overlay; Then: UIView *tempOverlay = [[UIView alloc] initWithFrame:CGRectMake(160.0f, 70.0f, 150.0f, 310.0f)]; self.overlay = tempOverlay; [tempOverlay release]; Isn't the tempOverlay variable above unnecessa...

How to release object passed to protocol or delegate method in Objective-c?

How and when is released IndexPath object which is returned in UITableViewDelegate? let's imagine code: //my method in my object { NSNumber *number=[[NSNumber alloc] init]; number=[[self methodreturningnumber] retain]; [delegate didSelectItemAtIndex:number]; } in my delegate I have method: -(void)didSelectItemAtIndex:(N...

Adding @Property UISwitch to TableView Causes RetainCount Problems

I am doing this with UISwitchs and UITextFields... I have declared the UISwitch as Property in the header file, because I want to access its value in several different methods within my class. I am adding the UISwitch to one of my TableViewCells, using the following code: - (UITableViewCell *)tableView:(UITableView *)tableView cellFo...