[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bogus retain via NSEnumerator
From: |
James Spencer |
Subject: |
Re: bogus retain via NSEnumerator |
Date: |
Tue, 20 Apr 2004 19:51:29 -0500 |
User-agent: |
Thoth/1.7.2 (Carbon/OS X) |
In article <2c4a8c18.0404200922.526e6521@posting.google.com>, Wayne
Cochran <wcochran@acm.org> wrote:
> The Cocoa version of autorelease and the one documented in
> the O'Reilly "Objective-C Pocket Reference" differ greatly. I like the idea
> of autorelease sending a release message to the object as soon
> as the callee's stack frame is destroyed -- that makes a lot sense
> and is consistent with how local object's (i.e. stack
> allocated) are deallocated in C++.
>
> This whole idea of autorelease pools seems a little strange to me and seems
> as error prone as performing my own explicit memory management.
> But I am new to Cocoa's memory management scheme, so the jury
> is still out.
You are comparing Apple's and oranges! All (repeat: ALL) objects in
Objective C are dynamically allocated; none are allocated on the stack.
Even in C++, dynamically allocated objects created with new are not
automatically destroyed just because a variable that REFERENCES the
object goes out of scope.
The autorelease mechanism works very well once you understand it. The
advantage is that typically a method caller who gets a pointer to an
object back from the call doesn't have to do anything with it in terms
of retaining it or destroying it. In C++, you would have to
explicitly destroy the reference.
Spence
--
James P. Spencer
Rochester, MN
"Badges?? We don't need no stinkin badges!"
- Re: bogus retain via NSEnumerator, Michael Ash, 2004/04/20
- Re: bogus retain via NSEnumerator,
James Spencer <=
- Re: bogus retain via NSEnumerator, John C. Randolph, 2004/04/21
- Re: bogus retain via NSEnumerator, David Stes, 2004/04/21
- Re: bogus retain via NSEnumerator, Pete French, 2004/04/21
- Re: bogus retain via NSEnumerator, Sherm Pendley, 2004/04/21
- Re: bogus retain via NSEnumerator, David Stes, 2004/04/21
- Re: bogus retain via NSEnumerator, Glenn Andreas, 2004/04/21
- Re: bogus retain via NSEnumerator, Michael Ash, 2004/04/22
- Re: bogus retain via NSEnumerator, John C. Randolph, 2004/04/22
- Re: bogus retain via NSEnumerator, David Stes, 2004/04/22