Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with [NSArray count]



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Problems with [NSArray count] (From: Peter Browne <email@hidden>)
 >Re: Problems with [NSArray count] (From: David Duncan <email@hidden>)
 >Re: Problems with [NSArray count] (From: Peter Browne <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.