• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Ugly bug in Foundation, beware!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Ugly bug in Foundation, beware!
      • From: Tom Harrington <email@hidden>
References: 
 >Ugly bug in Foundation, beware! (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Ugly bug in Foundation, beware!
  • Next by Date: Re: Ugly bug in Foundation, beware!
  • Previous by thread: Re: Ugly bug in Foundation, beware!
  • Next by thread: Re: Ugly bug in Foundation, beware!
  • Index(es):
    • Date
    • Thread