gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnustep-cvs] r31629 - in /libs/back/trunk: ./ Source/cairo/ Source/


From: David Chisnall
Subject: Re: [Gnustep-cvs] r31629 - in /libs/back/trunk: ./ Source/cairo/ Source/gsc/ Source/win32/ Source/winlib/ Source/x11/
Date: Sat, 20 Nov 2010 13:20:37 +0000

On 20 Nov 2010, at 12:57, Nicola Pero wrote:

> On 20 Nov 2010, at 12:44, David Chisnall wrote:
> 
>> objc_malloc() and friends are GCC-runtime specific.  They are not supported 
>> by other runtimes.  If there is a reason for avoiding malloc(), using either 
>> NSZoneMalloc() or NSAllocateCollectable() should be the preferred 
>> indirection.
> 
> Using malloc() is usually wrong as it can't work with garbage collection. ;-)

I'd replace 'usually' with 'sometimes' there.  malloc() is absolutely fine (and 
should be preferred) as long as it is not used to store object pointers and it 
is matched with free() in -finalize.  I'd also add that it CAN be used with 
object pointers as long as CFRetain() is called on them (rather than -retain) 
in Apple-land, so we should support this in GNUstep.  Of course, if you're 
storing object pointers then NSMutableArray is probably a better bet.

Using objc_malloc() for something that is stored in an ivar and contains 
non-object types is almost always wrong - you're burdening the GC for no 
benefit.

David


reply via email to

[Prev in Thread] Current Thread [Next in Thread]