Beomseok
Beomseok

Reputation: 471

How to autorelease in Objective - c

I'm not using Autorelease. When I use like this code, I don't know How to release BSPTile

    NSUInteger numbToday = [[dateFormatter stringFromDate:[NSDate date]] intValue];
    BSPTileView *tile = [gridView.subviews objectAtIndex: 0];
    tile.comparedValue = 0;

BSPTileView is UIView Class. How to do ? please.

Upvotes: 0

Views: 112

Answers (3)

David
David

Reputation: 9945

If you have your BSPTileView inserted in a view hierarchy, the hierarchy takes care of managing the object for you. Taking the object from the subviews array does not change the retain count. No responsibility is transfered.

Upvotes: 0

Noah Witherspoon
Noah Witherspoon

Reputation: 57149

In this case, you don't have to. -objectAtIndex: just returns the object at that index in the array, without changing its retain count.

Upvotes: 1

Dave DeLong
Dave DeLong

Reputation: 243146

You don't. You did not receive this pointer via a method call that contains new, alloc, retain, or copy, so you are not responsible for releasing (or autoreleasing) the pointer.

If your application is structure such that you have to release it here, then you've done something wrong somewhere else.

Upvotes: 1

Related Questions