Le 23 juin 2010 à 12:14, Ben Haller a écrit :

> 
>  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?


In fact, this is not contradicted by the documentation:

See the  "Resource Management" section in "Memory Management programming guide"

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/20000043-SW6

«You should typically not manage scarce resources such as file descriptors, 
network connections, and buffers/caches in a dealloc method. In particular, you 
should not design classes such that you are assuming that dealloc will be 
invoked when you think it will be invoked. Invocation of dealloc might be 
delayed or sidestepped, either because of a bug or because of application 
tear-down.

Instead, if you have a class whose instances manage scarce resources, you 
should design your application such that you know when you no longer need the 
resources and can then tell the instance to “clean up” at that point. You would 
typically then release the instance and dealloc would follow, but you will not 
suffer additional problems if it does not.»


-- Jean-Daniel




_______________________________________________

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