Re: Leaking Memory
Re: Leaking Memory
- Subject: Re: Leaking Memory
- From: mmalcolm crawford <email@hidden>
- Date: Wed, 22 Jan 2003 17:32:42 -0800
On Tuesday, January 21, 2003, at 03:12 AM, Robert Goldsmith wrote:
I saw nothing wrong with the simplification as a starting point to
grasp memory management.
On the contrary, there was a fundamental inaccuracy in two statements:
On Monday, January 20, 2003, at 04:19 PM, David Cairns wrote:
release -- deallocates an object _right away_
autorelease -- deallocates an object when you don't need it anymore
(generally at the end of whatever method the autorelease is declared)
Deallocate is *not* the same as "decrement the retain count".
Furthermore, the following is at best misleading:
The important thing to remember about convience constructors is that
the objects they return are _already autoreleased_. That means that
if you try to send a release or autorelease to an object created with
a convience constructor you will either get a signal 10 (SIGBUS) or 11
(SIGSEGV) error, which is of course, bad. Here's an example:
MyClass *myObject = [MyClass objectWithStuff: stuff];
there you go. that's all. DON'T TRY TO [myObject release] WHATEVER
YOU DO!
The obvious counter-example is:
MyClass *myObject = [MyClass objectWithStuff: stuff];
[myObject retain];
...
[myObject release];
I have been told that all these issues are reasonably well covered at:
http://www.stepwise.com/Articles/Technical/2001-03-11.01.html
If you need more detail, see the other articles at Stepwise and
elsewhere, and the now copious documentation and archives.
A final point, at the risk of appearing tetchy (not my intent): I'm not
sure I see the need for everyone to re-write their own answer to memory
management questions every time they arise -- especially if they don't
get the answer right?! Surely one of the tenets of OOP is *reuse*...
:-)
mmalc
_______________________________________________
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.