Re: Ugly bug in Foundation, beware!
Re: Ugly bug in Foundation, beware!
- Subject: Re: Ugly bug in Foundation, beware!
- From: Brent Gulanowski <email@hidden>
- Date: Thu, 3 Jun 2004 11:00:56 -0400
On Jun 3, 2004, at 9:05 AM, Ondra Cada wrote:
>
Hi all,
>
>
just bumped into this: mutable arrays do *NOT* deep copy upon receiving
>
-copy
>
>
#import <Foundation/Foundation.h>
>
int main() {
>
[NSAutoreleasePool new];
>
id a=[NSMutableArray arrayWithObject:[NSMutableArray array]],b=[a
>
copy];
>
NSLog(@"contents: %x %x",[a lastObject],[b lastObject]);
>
// this is why it is very very bad
>
[[a lastObject] addObject:@"this is WAY wrong if seen in b!!!"];
>
NSLog(@"changed a, my private b is %@",[b description]);
>
return 0;
>
}
>
>
Didn't check mutable sets, dicts, et cetera, but i'd bet they share
>
this howler :(((((
Did you file a bug report? I agree that this is a bug. I guess the
workaround, short of writing your own -copy method, is to archive and
unarchive. Then you also get the feature of automatically handling and
resolving any reference/retain loops. Although I think mutual retains
like Clarke's sample are a programmer's bug.
--
Brent Gulanowski email@hidden
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.