Re: Initializing an Array
Re: Initializing an Array
- Subject: Re: Initializing an Array
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 22 Jan 2002 13:35:59 -0800
On Tuesday, January 22, 2002, at 01:19 PM, Jeff Galyan wrote:
>
Well, here's the rub: when I malloc or calloc something and
>
then free it
>
after use (in Cocoa, and after ensuring it's non-NULL), I get a
>
segfault
>
when the ObjC runtime tries to free it again.
Well, of course. If you want NSObject's -dealloc method to free
some memory, you shouldn't be doing it, too.
It sounds like your problem is a result of mixing malloc() with
+alloc. If you're allocating storage for an Obj-C instance,
don't use malloc(), use +alloc. If you want an
arbitrarily-sized block of bytes, try using NSData and
NSMutableData.
-jcr
"This is not a book to be tossed aside lightly. Rather, it
should be hurled with great force." -Dorothy Parker