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

Posing as NSPort



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?

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.

btw, all this effort is an attempt to figure out how to properly clean 
up after an inter-thread cross-over style DO transaction (e.g. 
SimpleThreads DTS code) without leaking ports all over the place.

Thanks

John

On Friday, March 15, 2002, at 12:00 PM, Chris Kane wrote:

> NSPort is an abstract class, so no real instances of it should ever 
> exist.  When you think you're allocating one, it is allocating an 
> instance of a concrete class (like NSMachPort), and of course anything 
> typed as NSPort * might be an instance of any subclass of NSPort.
>
> If you subclass an abstract class, you usually have to implement the 
> interesting guts of the class; otherwise, the class wouldn't be 
> abstract.
>
> Your posing as NSPort probably is working, but since the concrete 
> subclasses may be overriding retain/release for their own purposes, it 
> won't do much good.
>
> Chris Kane
> Cocoa Frameworks, Apple
>
> On Friday, March 15, 2002, at 12:28 AM, John Saccente wrote:
>
>>
>> I want to pose as NSPort to watch retain/release activity during some 
>> DO maneuvers, but I'm having no luck.  I get the impression that there 
>> is some funny business going on when you create an NSPort object, as I 
>> never see any actual instances of "NSPort" listed in ObjectAlloc, only 
>> CFMachPorts created in their place.  But clearly I'm manipulating 
>> NSPort objects in my code, so this is very confusing.  Using 
>> subclassed NSPort objects doesn't work either, since the framework 
>> seems to notice that I'm using a subclass in place of a proper NSPort 
>> and expects me to implement some special behaviors that I'm 
>> ill-prepared to offer.  I have no trouble similarly posing as other 
>> classes, but NSPort has me baffled.
>>
>> John Saccente
>> jsaccente@xxxxxxx
>>
>> _______________________________________________
>> MacOSX-dev mailing list
>> MacOSX-dev@xxxxxxxxxxxxx
>> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>
> _______________________________________________
> MacOSX-dev mailing list
> MacOSX-dev@xxxxxxxxxxxxx
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>