Re: EXC_BAD_ACCESS in an strange place
Re: EXC_BAD_ACCESS in an strange place
- Subject: Re: EXC_BAD_ACCESS in an strange place
- From: Isaac Sherman <email@hidden>
- Date: Fri, 23 Aug 2002 13:16:33 -0400
on 8/23/02 12:33 PM, the method -(id)email@hidden:(id) sender:@"Clark
Mueller"; returned:
>
> filesArray = [[NSArray alloc] init];
>
>
>
> while( file = [de nextObject] ){
>
> if( [ig fileExists:[folder stringByAppendingPathComponent:file]] )
>
> filesArray = [filesArray arrayByAddingObject:[folder
>
> stringByAppendingPathComponent:file]];
>
>
>
> NSLog(@"%d: %@", [filesArray count]-1, [filesArray
>
> objectAtIndex:[filesArray count]-1]);
>
> }
>
>
>
> NSLog(@"[filesArray count] == %d", [filesArray count]);
>
>
Now, this was causing a crash. I added a line to the above code:
>
>
> [filesArray retain]
I recommend using an NSMutableArray and just using addObject:, less memory
management involved.
>
And it worked fine.
>
>
I'm left then with my original question: What was happening? Why wasn't
>
my check for filesArray == nil catching this? Memory management really
>
gives me a headache.
Hmm. IIRC, I had a similar problem with NSString; I would alloc the
string, assign it a string, and myString==nil would return NO, even though
the string was empty. [myString compare:@""] would return NSOrderedSame,
however, and that's how I got around that. What I would suggest is perhaps
sending an isEqualTo: message, passing a freshly alloced empty array as the
argument.
HTH,
--
Isaac Sherman
MotaSoft Software
http://homepage.mac.com/huperzoevs/
_______________________________________________
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.