• 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: reason for getting NSFileHandle:writeData exception
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reason for getting NSFileHandle:writeData exception


  • Subject: Re: reason for getting NSFileHandle:writeData exception
  • From: Brian Stern <email@hidden>
  • Date: Tue, 10 Jul 2007 12:32:15 -0400

Chris,

Take Andrew's advice and read the docs. Obviously the basic idea is that you retain an object when you want it to stick around for longer than the current method.

Just to make clear what happened:

You created an autoreleased file handle and assigned its pointer to an instance variable. The file handle was released automatically by the current autorelease pool at the end of the current event loop. This created a stale pointer. Your instance variable now pointed to a place in memory where the file handle used to be. A new object, a string, was created somewhere in your application and was assigned to the same location in memory that your file handle had used. When your code got around to using the stale file handle instance variable there was a string there instead of the file handle that your code expected.

This is a common beginner's mistake. You'll have to read the memory documentation several times, and of course write some code, to really understand how the memory model works.

Good luck,

Brian


On Jul 10, 2007, at 12:57 AM, Chris Heimark wrote:

Sure seems like I have a trashed "outputFileHandle", doesn't it? Well, here is how I was creating the handle:

outputFileHandle = [NSFileHandle fileHandleForWritingAtPath: [savePanel filename]];

Then I tried a little bit of retention to keep it around!

outputFileHandle = [[NSFileHandle fileHandleForWritingAtPath: [savePanel filename]] retain];

And what do you know? IT WORKS NOW!!!

Perhaps you can provide some insight as to when retain/release is needed?

On Jul 9, 2007, at 8:15 PM, Brian Stern wrote:

And here is the code that runs in an NSTask callback occurring as a result of running an external command line program and trying to absorb the binary results using an NSData object.

>>>>>
	[outputFileHandle writeData:rngData];


The exception indicates that the code is trying to send the writeData message to an NSString. So outputFileHandle is an NSString, not a file handle. Perhaps you're not retaining the file handle correctly or you're accessing it from multiple threads incorrectly.


--
Brian Stern
email@hidden

-- Brian Stern 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


  • Follow-Ups:
    • Re: reason for getting NSFileHandle:writeData exception
      • From: Chris Heimark <email@hidden>
References: 
 >reason for getting NSFileHandle:writeData exception (From: Chris Heimark <email@hidden>)
 >Re: reason for getting NSFileHandle:writeData exception (From: Brian Stern <email@hidden>)
 >Re: reason for getting NSFileHandle:writeData exception (From: Chris Heimark <email@hidden>)
 >Re: reason for getting NSFileHandle:writeData exception (From: Brian Stern <email@hidden>)
 >Re: reason for getting NSFileHandle:writeData exception (From: Chris Heimark <email@hidden>)

  • Prev by Date: Re: Discovering USB devices
  • Next by Date: [job posting] Senior Mac Software Developer (music 2.0) - Tuneup Media, Inc.
  • Previous by thread: Re: reason for getting NSFileHandle:writeData exception
  • Next by thread: Re: reason for getting NSFileHandle:writeData exception
  • Index(es):
    • Date
    • Thread