Re: Cocoa - Naive questions about memory
Re: Cocoa - Naive questions about memory
- Subject: Re: Cocoa - Naive questions about memory
- From: j o a r <email@hidden>
- Date: Tue, 6 May 2003 13:04:59 +0200
Do you look at the warnings that the compiler give you?
1)
This is just plain wrong:
localArray = [[NSArray init] alloc];
If anything, it should have been:
localArray = [[NSArray alloc] init];
...but what you'd like to do with an empty immutable array is lost on
me.
2)
Imediately after creating (?) the localArray you replace it with an
autoreleased array returned from the "selectedCells" method. The first
array you created is now lost forever = leaked. The array you replaced
it with is already released, and hence you will crash if you release it
again.
Just do this:
{
NSEnumerator *enumerator = [[myMatrix selectedCells] objectEnumerator];
id obj;
while ((obj = [enumerator nextObject]))
{
// stuff
}
}
j o a r
On Tuesday, May 6, 2003, at 12:44 Europe/Stockholm, Jacques wrote:
It's simple but sometime, I have some trouble.
Imagine this kind of code :
{
NSArray *localArray;
localArray = [[NSArray init] alloc];
localArray = [myMatrix selectedCells];
NSEnumerator *enumerator = [localArray objectEnumerator];
id object;
while(object = [enumerator nextObject])
{
.../...
}
// I don't need localArray now
[localArray release];
}
With the [localArray release] line my programm crash with a SIGBUS
error. If i comment this line, my programm work but it seems that there
is a release missing... No ?
What do you thing about that ?
_______________________________________________
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.