• 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
Leaking: NSFileHandle readInBackgroundAndNotify
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Leaking: NSFileHandle readInBackgroundAndNotify


  • Subject: Leaking: NSFileHandle readInBackgroundAndNotify
  • From: Andreas Mayer <email@hidden>
  • Date: Wed, 2 Oct 2002 02:20:26 +0200

Am Montag, 30.09.02 um 04:24 Uhr schrieb Andreas Mayer:

After moving to 10.2 I noticed that my application would not close the serial port properly anymore.

Looks like NSFileHandle's readInBackgroundAndNotify does retain the receiver.

Is this correct behaviour?
Since my app worked before 10.2 I assume that it did not do that as of 10.1.x.

If this behaviour *is* correct, how should I go about releasing the file handle? closeFile does not help.

I created the NSFileHandle using initWithFileDescriptor:closeOnDealloc:

Can anyone verify my observations?

OK, I checked this again using ThreadViewer. I'm leaking NSFileHandles.

I use this for opening the device:

fileDescriptor = open(bsdPath, O_RDWR | O_NOCTTY | O_NDELAY);
[... some error handling and setting options ...]
// Success
fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fileDescriptor closeOnDealloc:NO];

(I tried with closeOnDealloc:YES too - no change)

then I eventually begin listening:

// getData will be called when data is available
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getData:) name:NSFileHandleReadCompletionNotification object: fileHandle];
[fileHandle readInBackgroundAndNotify];

(retain count is up one after readInBackgroundAndNotify)

and when I don't need it anymore, I close the device:

if (fileDescriptor >= 0) {
[.. error handling and resetting options ...]
[fileHandle closeFile];
[fileHandle release];
close(fileDescriptor);
fileDescriptor = -1;
}

(retain count does not decrease with closeFile)

So after this I have a NSFileHandle hanging around that is effectively keeping the file/device open.

Does nobody else have any problems with this?


bye. Andreas.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: [NOT NEWBIE]launching tasks as root
  • Next by Date: Re: UML and Cocoa (again...)
  • Previous by thread: Re: [NOT NEWBIE]launching tasks as root
  • Next by thread: Re: Best way to sort a dictionary by value?
  • Index(es):
    • Date
    • Thread