Re: Who is releasing my CFAllocator?
Re: Who is releasing my CFAllocator?
- Subject: Re: Who is releasing my CFAllocator?
- From: Nat! <email@hidden>
- Date: Sun, 4 Aug 2002 01:42:56 +0200
Am Sonntag den, 4. August 2002, um 01:20, schrieb Ali Ozer:
Thanks for the reply, I cleared up most of my problems.
turns out I am confused by the documentation. The example says:
static CFAllocatorRef myAllocator(void) {
static CFAllocatorRef allocator = NULL;
if (!allocator) {
CFAllocatorContext context = {0, NULL, NULL, (void
*)free, NULL, myAlloc, myRealloc, myDealloc, NULL};
context.info = malloc(sizeof(int));
/* The info field points to an int which keeps */
/* track of the number of allocations/deallocations */
*(int *)(context.info) = 0;
allocator = CFAllocatorCreate(NULL, &context);
}
return allocator;
}
Is it required that the info fields first entry is an int ?
No.
Why would (void *) free be a suitable value for the release
pointer ( CFRelease( CFRetain( myAllocator()))...) ?
The info field points to whatever you want; it's there for your
custom allocator to do its job. The retain and release functions
(3rd and 4th fields in the context) apply to the info field. In
the above case, the info field is a malloc'ed block; the retain
func is set to nothing, and the release func is set to free(), to
free the block when the allocator goes away. I think calling
these retain/release is part of the confusion...
Yeah probably - I am still confused on this part. So release is
actually rather dealloc then ? But what is retain then for, who
calls it when ? Under what circumstances does setting the retain
function to something non-NULL make sense ? Maybe this will lift
the fog :)
Ciao
Nat!
Jedenfalls sind zehn Fehlstarts hintereinander [E. Fuchs]
ein sehr interessanter Beweis
fuer unsere Theorie
von der natuerlichen Ueberlegenheit des Dezimalsystems
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.