• 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: Two arrays sharing the same adress space.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two arrays sharing the same adress space.


  • Subject: Re: Two arrays sharing the same adress space.
  • From: Andy Lee <email@hidden>
  • Date: Mon, 17 Nov 2008 10:12:41 -0500

On Nov 17, 2008, at 10:01 AM, Scott Ribe wrote:
Mounts is being used, but just not in the init function.

You have declared it as a local variable. It *cannot* be used elsewhere.


I suspect that you have also declared it as a member (attribute, property,
whatever) and expect that you're assigning to that, but the local variable
will shadow that, and so there's your problem.

He may have that problem as well, but improper separation of alloc from init as explained earlier was definitely causing the symptom described. It's trivial to reproduce:


    NSMutableArray *mounts;
    NSMutableArray *bonjourServices;

mounts = [[NSMutableArray alloc] init];
[mounts initWithContentsOfFile:@"NonexistentFile"]; // causes dealloc
bonjourServices = [[NSMutableArray alloc] init]; // reuses dealloced memory


NSLog(@"mounts = [%X], bonjourServices = [%X], equal? %d", mounts, bonjourServices, mounts == bonjourServices);


This gives me:

2008-11-17 10:10:53.285 Scratch2[21580:10b] mounts = [1317D0], bonjourServices = [1317D0], equal? 1

--Andy

_______________________________________________

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


References: 
 >Re: Two arrays sharing the same adress space. (From: Scott Ribe <email@hidden>)

  • Prev by Date: Re: Two arrays sharing the same adress space.
  • Next by Date: Can you @synthesize simple arrays?
  • Previous by thread: Re: Two arrays sharing the same adress space.
  • Next by thread: Re: Two arrays sharing the same adress space.
  • Index(es):
    • Date
    • Thread