Re: Who is releasing my CFAllocator?
Re: Who is releasing my CFAllocator?
- Subject: Re: Who is releasing my CFAllocator?
- From: Nat! <email@hidden>
- Date: Sat, 3 Aug 2002 23:41:51 +0200
Am Mittwoch den, 31. Juli 2002, um 20:46, schrieb Nat!:
Am Mittwoch den, 31. Juli 2002, um 03:55, schrieb Ali Ozer:
If I create my own CFAllocator, it might be unavoidable that some
objects are created off it. Now these objects might be retained
so it's probably outside my scope to determine, when to get rid
of the CFAllocator. There is a "retain"/"release" call back...
Should my CFAllocator look for a release count of zero and
release itself or is this done my CoreFoundation automatically ?
CF will retain/release the allocator it's been given when it
allocates a CF object using an allocator. This is not true for
arbitrary memory allocated with an allocator though.
Ali
Yeah OK, but I don't see how this answers my question. Or is this
saying, that once I created an allocator and let CF use it, that I
should NOT deallocate it ?
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 ? Why
would (void *) free be a suitable value for the release pointer
( CFRelease( CFRetain( myAllocator()))...) ?
Is the custom CFAllocator's code remembering the number of
allocations/deallocations in the first info int ? As far as I
understand it the retain and release callbacks
const void *(*retain)(const void *info);
void (*release)(const void *info);
are for the allocator "object" itself - so the number of
allocations/deallocations would have to be tracked - if so
desired - manually in allocate/reallocate/deallocate.
Lets assume I am a short-lived factory that provides CF objects
using an equally (or ?) short-lived custom allocator. It would be
impractical to burden the user with the knowledge, that he should
retain a custom allocator. So my allocator will be released at the
end of the factory life but should only dealloc itself, when the
number of "free" calls have reached the number of "malloc" calls..
Does that sound right ?
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.