Re: Problems with [NSArray count]
Re: Problems with [NSArray count]
- Subject: Re: Problems with [NSArray count]
- From: "Shawn Erickson" <email@hidden>
- Date: Tue, 22 Apr 2008 15:04:33 -0700
On Tue, Apr 22, 2008 at 2:45 PM, Peter Browne
<email@hidden> wrote:
> I'm getting an "EXC_BAD_ACCESS" error.
>
> I've since managed to solve the problem by inserting a
>
> [myArray retain];
>
> but I'm not entirely sure WHY this fixed it...
>
> The process followed is:
>
> 1) the myController object acquires data from a text file, using NSString's
> -stringWithContentsOfFile:encoding:error
> 2) myArray then grabs this data (a bunch of numbers) using NSArray's
> -componentsSeparatedByString:
> 3) myController then passes the myArray object to myView (for later graph
> drawing) using my - (void)displayData:(NSArray *)theArray method
> 4) myView then calls [theArray count]
> 5) EXC_BAD_ACCESS
>
> inserting a [myArray retain] just before passing the data to the view fixed
> the problem. Why should this be the case?
> As far as I'm aware the object isn't being released at that point, so
> what's the need for a -retain message?
Read the following carefully (in particular for the issue biting you
look for any discussion on "convenience" methods/constructors and the
use of proper accessors)...
<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/index.html>
-Shawn
_______________________________________________
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