[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Releasing objects declared in method?
From: |
Pete French |
Subject: |
Re: Releasing objects declared in method? |
Date: |
Sat, 10 May 2003 13:53:13 +0100 |
> tmpObject = [[NSMutableArray arrayWithCapacity: 8]
> initWithCapacity: 8];
You dont need the 'init' method here - the 'arrayWithCapacity' method
has already doe this for you. You only need init after alloc.
> 1. Do I need to release tmpObject *explicitly*?
Not if you use the 'arrayWithCapacity' method to create it, no.
> 3. If I need to release it before the method ends, does it mean that I
> can't use "return [tmpObject count]" statement?
If you *did* release it then you would not be able to use the 'count'
method. But the way you are doing it is fine. I'd probably just write it
as
- (int)trivialMethod
{
NSMutableArray *tempArray = [NSMutableArray array];
[tempArray addObject: something];
.... add some objects ....
return [tempArray count];
}
-bat.