Re: Why I have a leak? I am unable to understand
Re: Why I have a leak? I am unable to understand
- Subject: Re: Why I have a leak? I am unable to understand
- From: Nathan Vander Wilt <email@hidden>
- Date: Mon, 24 Aug 2009 17:25:39 -0700
On Aug 24, 2009, at 5:20 PM, Agha Khan wrote:
HI:
I know the leak is in next 2 lines
I have commented all the code except these 2 lines.
// NSTimeInterval
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |
NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit |
NSSecondCalendarUnit;
NSDateComponents *dateSegments = [gregorian components:unitFlags
fromDate:[NSDate date]];
I am not releasing gregorian, because I never used retain.
Same is true with dateSegments.
Can someone help me.
Why I have a leak? I am unable to understand?
From http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html
"You own any object you create.
You “create” an object using a method whose name begins with “alloc”
or “new” or contains “copy” (for example, alloc,newObject, or
mutableCopy)."
You created gregorian using [NSCalendar alloc], so you own it. The
next rule on that page says:
"If you own an object, you are responsible for relinquishing ownership
when you have finished with it.
You relinquish ownership of an object by sending it a release message
or an autorelease message (autorelease is discussed in more detail in
“Delayed Release”). In Cocoa terminology, relinquishing ownership of
an object is typically referred to as “releasing” an object."
hope this helps,
-natevw
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden