Comrades:
I have experimented a bit with this, and I think I have something
that works, but I would like to understand it better. I am reading
the Hillegass book, but I don't really see an example of what I am
tryng to do, although it seems like a very basic question.
The Question:
If I
On Jun 27, 2008, at 4:22 PM, Paul Archibald wrote:
I am reading the Hillegass book, but I don't really see an example
of what I am tryng to do, although it seems like a very basic
question.
[...]
But, as I have been trying to make an exhaustive test of what
works and what crashes, I
The details of memory management take a long time to understand
fully, but there are some basic simple principles that will really
help you out.
1. When you get an object from a method that starts with alloc or
new, or contains the word copy in it, YOU own that object. The
retain count
Here is a simple example:
-(NSArray*) makeObject {
NSArray *a = [NSArray arrayFromObjects];someObject, anotherObject,
nil];
This should be NSArray *a = [NSArray arrayFromObjects:someObject,
anotherObject];
// should I [a retain];
I would use [a retain];
// or [a release];
On Fri, Jun 27, 2008 at 5:19 PM, Daniel Richman
[EMAIL PROTECTED] wrote:
Here is a simple example:
-(NSArray*) makeObject {
NSArray *a = [NSArray arrayFromObjects];someObject, anotherObject,
nil];
This should be NSArray *a = [NSArray arrayFromObjects:someObject,
anotherObject];
Then you'd be wrong. You should use [a autorelease];
G.
On 28 Jun 2008, at 10:19 am, Daniel Richman wrote:
I would use [a retain];
___
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments
Actually, in the context of this:
NSArray *a = [NSArray arrayFromObjects:someObject, anotherObject, nil];
you would do nothing, since that method returns an autoreleased
NSAarray already.
But in a situation where you alloc/inited an object, you would
autorelease before returning it.