On Mar 28, 2010, at 9:32 AM, Clark Cox wrote:

>> When importing header files into my
>> implementation file ".m", do I #include them or #import them? How about
>> existing library headers (like <string.h>)?
> 
> You can do either.

To be precise: #import is just like #include, except that the second #import of 
the same path does nothing. So in almost any case it’s safe to #import regular 
C headers, since it’s a very rare header that’s meant to be imported multiple 
times.

> 
>> 2) If my C code uses malloc/free, and my ObjC project has garbage collection
>> turned on, what 'gotcha's do I have to watch out for? What if GC is turned
>> off (for iPhone)?
> 
> The Garbage collector completely ignores memory allocated via malloc.
> Regardless of whether or not GC is on, you are still responsible for
> free()'ing malloc()'ed memory.

The main requirement here is that a class that causes memory to be malloc’ed 
has to have a -finalize method that frees that memory. (Very often the 
-finalize will be identical to the -dealloc.) This applies whether you called 
malloc directly, or some C/C++ library [including CF] that allocated memory for 
you. In the latter case of course you have to issue the corresponding clean-up 
calls.

—Jens

_______________________________________________

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