Re: Memory Mysteries
Re: Memory Mysteries
- Subject: Re: Memory Mysteries
- From: David P Henderson <email@hidden>
- Date: Fri, 25 Jul 2003 22:58:28 -0400
Read _Object_Ownership_and_Disposal_
<
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
index.html#//apple_ref/doc/uid/10000011i>
"..., Cocoa sets this policy: If you directly create an object (using
alloc ,allocWithZone: , or new ) or copy an object (using copy
,copyWithZone: ,mutableCopy , or mutableCopyWithZone: ), you are
responsible for releasing it. If you did not directly create or copy
the object, you do not own it and should not release it ."
Applied to your examples:
On Friday, 25 July 2003, at 19:54PM, email@hidden wrote:
>
I'm a little confused about managing memory in cocoa. I know I should
>
release objects that have been allocated like this:
>
NSObject *object = [[NSObject alloc] init];
>
You created it; you own it; you are responsible for making it go away
at the appropriate time.
>
But do you release things like this?
>
NSFileManager *fm = [NSFileManager defaultManager];
>
You didn't create it; you don' t own it; you aren't responsible for it.
>
Or things like this:
>
>
NSString *string = [@"~/Desktop/" stringByExpandingTildeInPath];
>
You didn't create it; you don' t own it; you aren't responsible for it.
Dave
--
Chaos Assembly Werks
"The Trend over the last 20 years or so has been to design computer
languages that enforce a state of paranoia. You're expected to program
every module as if it were in a state of siege In Perl culture, by
contrast, you're expected to stay out of someone's home because you
weren't invited in, not because there are bars on the windows."
from Programming Perl
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.