Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jagatnibas

macrumors regular
Original poster
Jul 28, 2008
126
0
I am trying to download iOS5 sdk. The account I login with is an administrator account created for me by my team agent. I see 2 links, one is xcode 4 for lion and then xcode 4 for snow leopard, but when i click, i get access denied message. code P1 contact support ! when i try download xcode 4 for lion, it does not download rather says need 10.7, I am on 10.6.8 Whats d solution and is it that only team agents can download iOS5 sdk ?

I have 2 situations.

i have an array alloced and retained as member variable. i release it in dealloc. i create a button by alloc and add this to member array, if i do not release button, do I leak ? static analizer says so ! what is the best way to fix leak in this case ?

thanks and regards
 
i have an array alloced and retained as member variable. i release it in dealloc. i create a button by alloc and add this to member array, if i do not release button, do I leak ? static analizer says so ! what is the best way to fix leak in this case ?

Yes. You alloc/init. The retain count is 1. You own this object. You add it to the NSArray. This retains it. Retain count is 2. You both own the object. You release the NSArray. It releases the button. Retain count is now 1 and you still own it. You have to release it.

The simplest thing to do is to autorelease it before adding it to the NSArray.
 
The simplest thing to do is to autorelease it before adding it to the NSArray.

I feel it is good practice for new developers to learn to avoid using the autorelease pool purely for convienience. Developers should learn to either call retain and release or let ARC handle things instead of putting extra work on the application by using the pool.
 
Ok, thanks gentlemen,

Now a few case studies where I should know whther i am leaking or best practice shot off. Please advise, thanks in advance

I am doing a custom cell and using following code

Static analyser gives a warning "receiver of frame is nil and hence returns garbage CGRect" ? why so ? I lblText is an outlet and I am setting outlet through nib file. When I run the code, there is no problem in functionality, it is only that static analyser in sdk 5.0 shouts here.

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
    static NSString *CellIdentifier = @"myCell";
    
    MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        
        NSArray * topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
        
        for(id currentObject in topLevelObjects)
        {
            if([currentObject isKindOfClass:[UITableViewCell class]])
            {
                cell = (MyCell *)currentObject;
                break;
            }
        }        
    }    
	
    if(selectedIndex == indexPath.row)
    {
		CGFloat labelHeight = 100;
		[B]CGRect rct = [[cell lblText] frame];[/B]
		[[cell lblText] setFrame: CGRectMake(rct.origin.x, 
												 rct.origin.y, 
												 rct.size.width, 
												 labelHeight)];
[[cell lblText] setFrame:@"My Text"];
}
}



Secondly,

If I have a few IBOutlets in a class, where should I call [outletobject release] ?
viewDidUnload or dealloc ? And where should I assign them to nil ?

if I have done alloc to a nonatomic retained variable in viewDidLoad where should I release them ? viewDidUnload or dealloc ?

in these cases static analyser is not shouting, though, I wanna do the best practice.

regards
 
Also, if I am using

Code:
UIImage *img = [UIImage imageNamed:@"myImage.png"];

after the usage is over, should i release img or not ?

Do I own img this way ?
 
Last edited by a moderator:
Also, if I am using

Code:
UIImage *img = [UIImage imageNamed:@"myImage.png"];

after the usage is over, should i release img or not ?

Do I own img this way ?

No you don't, you used an Convenience method, which means you give the ownership to the compiler, it will release it itself.
 
Last edited by a moderator:
Thanks a lot, I would be happy if you all know the static analyser warning or errors i posted,

regards
 
I am sorry if i could not make the point, I am talking about custom cell code in my post #4 and outlet questions !
 
Well, this looks suspicious:
Code:
[[cell lblText] setFrame:[COLOR="Red"]@"My Text"[/COLOR]];
setFrame: is expecting a CGRect not an NSString.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.