Re: Inconsistent Memory Management Rules
Re: Inconsistent Memory Management Rules
- Subject: Re: Inconsistent Memory Management Rules
- From: Denis Stanton <email@hidden>
- Date: Thu, 17 Apr 2003 09:34:19 +1200
Sherm
On Wednesday, April 16, 2003, at 06:10 PM, Sherm Pendley wrote:
>
On Tuesday, April 15, 2003, at 10:30 PM, Denis Stanton wrote:
>
>
> Really? That simple? No alloc or retain = no leak?
>
>
I wouldn't go quite *that* far... No +alloc, -copy, +new, or -retain
>
means that you're not responsible for releasing (or autoreleasing) the
>
object.
>
A leak is still quite possible - if, for example, the code that *is*
>
responsible for the object fails to release it properly.
OK, I knew I was over-simplifying a bit. Thanks for clarifying, and
adding -copy, +new and -retain to the list of initializers without
autorelease build in.
>
> I assumed that since I was using something called myDateString it
>
> must exist and therefore must be implicitly allocated space and
>
> therefore was a potential memory leak. As you saying that in my
>
> little example myDateString would just vanish when the method
>
> completed?
>
>
No, the methods you use to obtain myDateString - -objectAtIndex: and
>
-stringByAppendingString: are not one of the three methods that return
>
a retained object. In each case, the object you get back has either
>
been autoreleased for you, or is retained by a collection object that
>
has assumed responsibility for releasing it.
My general error here was in not appreciating (or not remembering,
because I must have read it somewhere in my studies) that some methods
will include autorelease. I had come to think that it was all down to
me, and I knew I wasn't doing it.
>
An autoreleased object does not vanish when the method completes. Its
>
retain count is decremented when the active NSAutorelease pool is
>
released. In a standard Cocoa app, a new pool is created at the start
>
of each event, and released when all processing is finished for that
>
event.
Yes, I knew that when I said "released" I should really have said
"retain count decremented". I was trying to keep it simple.
You have said something new here. I didn't realize that Autorelease
pools were created and released with each event.
Maybe this is too wide a question for this discussion, but what exactly
constitutes an event?
I used to write programs with event loops, but with OOD that is
somewhat hidden from me so the event cycle is less obvious.
I guess an IBAction is an event. What else? Any method that receives
a notification, like (void)tableViewColumnDidResize:(NSNotification
*)notification; ?
Anything that triggers activity in my program, like -(void)awakeFromNib
?
Denis
_______________________________________________
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.