• 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: Problems with [NSArray count]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with [NSArray count]


  • Subject: Re: Problems with [NSArray count]
  • From: David Duncan <email@hidden>
  • Date: Tue, 22 Apr 2008 16:08:37 -0700

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@hidden




_______________________________________________

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: 
 >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>)

  • Prev by Date: Re: NSString memory management question
  • Next by Date: [ANN] TransactionKit, Lockless Multi-Reader, Multi-Writer Transaction Capable Hash Tables
  • Previous by thread: Re: Problems with [NSArray count]
  • Next by thread: Re: Problems with [NSArray count]
  • Index(es):
    • Date
    • Thread