• 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: Chris Heimark <email@hidden>
  • Date: Tue, 10 Jul 2007 13:15:56 -0400

Thanks Brian, Kevin and Andrew.

I appreciate your rundown on this behavior. This memory model is convenient to those who understand it and a surprise to those of us just getting into Cocoa/ObjC.

In this case it was a surprise to me - because I'm unsure about why one would create such a short lived file handle. I was expecting it to be around until I no longer needed it. Lesson learned ;-)

Thanks to the list and to you all for your help!

Chris

On Jul 10, 2007, at 12:32 PM, Brian Stern wrote:

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

_______________________________________________

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: Kevin Kuehl <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>)
 >Re: reason for getting NSFileHandle:writeData exception (From: Brian Stern <email@hidden>)

  • Prev by Date: Re: Cross-platform toolkit with a Cocoa backend
  • Next by Date: NSTableView selectionShouldChangeInTableView: bug?
  • Previous by thread: Re: reason for getting NSFileHandle:writeData exception
  • Next by thread: Re: reason for getting NSFileHandle:writeData exception
  • Index(es):
    • Date
    • Thread