Re: deallocation of related objects
Re: deallocation of related objects
- Subject: Re: deallocation of related objects
- From: Philip Mötteli <email@hidden>
- Date: Wed, 12 Mar 2003 12:08:45 +0100
Hi
On Tuesday, March 11, 2003, at 08:31 PM, Daryn wrote:
When the object is destroyed, then the metadata needs to be freed.
This is a problem, I will soon have to deal too.
My first idea, was to point the ObjC deallocation function to my own
deallocation function, which would do its stuff and then call the
original deallocation function:
I'd take a look at /usr/include/objc/objc-runtime.h; specifically the
following section:
/* overriding the default object allocation and error handling routines
*/
OBJC_EXPORT id (*_alloc)(Class, unsigned int);
OBJC_EXPORT id (*_copy)(id, unsigned int);
OBJC_EXPORT id (*_realloc)(id, unsigned int);
OBJC_EXPORT id (*_dealloc)(id);
OBJC_EXPORT id (*_zoneAlloc)(Class, unsigned int, void *);
OBJC_EXPORT id (*_zoneRealloc)(id, unsigned int, void *);
OBJC_EXPORT id (*_zoneCopy)(id, unsigned int, void *);
Unfortunately, Timothy J. Wood said:
This doesn't work for all classes (or possibly any any more -- I
don't remember). For example, all the CoreFoundation classes (which
means NSString as the original question asked about) will not hit the
_alloc hook. They'll end up going through CFAllocator and then into
malloc. You might be able to write your own allocator and replace the
default allocator if you only want a limited set of objects.
So I asked him, what he would suggest:
Well, depending upon how transparent you want, you could use
+allocWithZone: and -dealloc, but as I noted, this will not catch
things like NSString and such.
Probably the best route it to create your own zone type (see
<objc/malloc.h>) and CFAllocator type. I don't recall if this has
happened yet, but Apple's plan is supposedly to make 'malloc_zone_t *'
and 'CFAllocatorRef' be interchangable, so you'd only have to do one.
For now, you could layer your CFAllocator on top of your > malloc_zone_t.
This doesn't give you the 'class' of the allocated memory, though
(well, neither would allocWithZone:). To deal with this, the CF
allocation event system has a event that sets the class name of a
block of memory.
I'd recommend looking at the CoreFoundation and malloc source,
available from Darwin for more info.
I'm not enough advanced yet, in order to attack the problem, but I
would be very interested, if this helped you and how you did solve the
problem.
Re
Phil
_______________________________________________
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.