On Apr 22, 2008, at 2:45 PM, Peter Browne wrote:

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?


First, read this: <http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html >

Once you have, you will note that the array returned by - componentsSeparatedByString: doesn't belong to you unless you retain it. You are likely getting your bad access because the autorelease pool is being drained in between your call to -displayData and -count (and -displayData: probably should be named -setDisplayData: instead).
--
David Duncan
Apple DTS Animation and Printing
[EMAIL PROTECTED]



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to