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

Posing as NSPort



On Friday, March 15, 2002, at 11:56 AM, John Saccente wrote:

>
> I've tried posing as NSMachPort, but I only see some methods like +port 
> and -init getting caught by my posing class.  The stack creating the 
> ports looks like:
>
> ...
> +[NSPort port]
> -[NSMachPort init]
> -[NSMachPort initWithMachPort:]
> CFMachPortCreateWithPort
> _CFRuntimeCreateInstance
> CFAllocatorAllocate
> malloc
>
> I don't understand why I don't see any NSMachPort objects showing up in 
> ObjectAlloc (that is, I see the total number increase, but the current 
> and peak values never do.)  Shouldn't there be a 1-1 correspondence 
> between the CFMachPort objects (which I *do* see being created) and 
> their "owning" NSMachPort objects?

These objects are both NSMachPorts and CFMachPorts due to the bridging, 
but ObjectAlloc only puts them in one bucket (or should in any case that 
it isn't).


> I can never capture retain/release method invocations.  I even tried 
> posing as NSObject and checking *all* of the retain/release invocations 
> for any sign of the id returned by [NSPort +port] and it never makes an 
> appearance.  The ids returned by +port match the pointers of the 
> CFMachPorts I see in ObjectAlloc, so I guess there's some NS/CF magic 
> going on underneath there that I'm failing to grok.

I think you're assuming -- in part (in posing as NSPort) -- that a 
subclass of NSPort would call super in methods the subclass overrides, 
but this isn't required.  As far as posing as NSMachPort goes, I would 
expect you to see all of the -retain/-release methods sent to such a 
thing, but it is always possible that no such messages are sent.  Go to 
the Instances tab in ObjectAlloc, select CFMachPort in the left column, 
then look at some of the objects and their retain/release events in the 
other columns -- if the backtraces in the event inspector contain 
-[NSMachPort retain] and so on for the retain/release events, then 
something is perhaps going wrong with the posing.  Though that would 
also be odd.  But more than likely you'll see the retains and releases 
using CFRetain/CFRelease, because they're happening down at the CF level 
mostly.


Chris Kane
Cocoa Frameworks, Apple