Hi all.  I'm using NSTask and NSPipe to launch lots of little processes, and 
I'm running out of file descriptors.  In my googling and archive searching, I 
found some info that led me to several approaches:

1. I ran ObjectAlloc and Leaks under Instruments and confirmed that I am not 
leaking pipes or file handles.  Nor is it an autorelease pool issue; the run 
loop is running freely as I start and stop tasks, so the pipes and file handles 
get dealloced properly.  All pipes and file handles made by my task code were 
listed by ObjectAlloc as "transitory".

2. I used "lsof -p <pid> | grep -v " txt " | wc -l" to monitor the file 
descriptors used by my app, and observed that it went steadily upwards as tasks 
got started and stopped; the file descriptors were not being freed, even though 
the pipes were being freed correctly.

3. I added [[pipe fileHandleForWriting] closeFile] and [[pipe 
fileHandleForReading] closeFile] calls to close the files associated with the 
pipes when my tasks completed.  This change fixed the problem; I no longer run 
out of file descriptors.

  So I have a workaround for the problem, but I want to understand *why* it 
works.  Shouldn't NSPipe close its associated files when it deallocs?  Why 
should it be necessary to call -closeFile?  This behavior seems to be 
specifically contradicted by the documentation on NSPipe, which says (in 
-fileHandleForReading) "The descriptor represented by this object is deleted, 
and the object itself is automatically deallocated when the receiver is 
deallocated."  Well, when my NSPipes are deallocated, the file handles are 
indeed automatically deallocated (a funny way to put it), but the descriptor is 
*not* deleted.  Is this a bug?  More likely I'm misunderstanding something; can 
anybody clarify this for me?

  Thanks!

Ben Haller
McGill University

_______________________________________________

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 arch...@mail-archive.com

Reply via email to