Re: Memory management with arrays
Re: Memory management with arrays
- Subject: Re: Memory management with arrays
- From: Scott Andrew <email@hidden>
- Date: Sat, 9 Feb 2008 22:16:26 -0800
Here is my guess, just because i hit this recently. It had to do with
the [bar autorelease] call. This returns an autoreleased object. That
may not be valid when you cam back around to removeAllObjects. Try the
following:
void foo
{
[array removeAllObjects];
Bar* bar = [[Bar alloc] init];
[array addObject:bar];
[bar release];
}
the following should also work..
void foo
{
[array removeAllObjects];
Bar* bar = [[[Bar alloc] init] autorelease];
[array addObject:bar];
}
Scott
On Feb 9, 2008, at 7:48 PM, Jacob Bandes-Storch wrote:
I have an array that is an instance variable. I'm trying to add an
object to it, and autorelease that object, so the next time this
happens, I can remove all objects in the array and the object will
be gone.
- (void)foo {
[array removeAllObjects];
Bar *bar = [[Bar alloc] init];
[array addObject:[bar autorelease];
}
This should remove all the objects, and add a new one. Basically, I
want the old Bar instance gone, and the new one in the array.
However, when I do this, I get an EXC_BAD_ACCESS when it tries to -
removeAllObjects. What's the problem?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden