CFMessagePort and GC
CFMessagePort and GC
- Subject: CFMessagePort and GC
- From: Ryan Brown <email@hidden>
- Date: Sun, 30 Nov 2008 21:15:43 -0800
Hi,
When a local CFMessagePort is invalidated it's underlying CFMachPort
isn't immediately invalidated. Instead, the mach port is invalided
when the message port is deallocated. I gleaned this by reading
through the CFMessagePort source code (the reason given in
CFMessagePortInvalidate() is "// For hashing and equality purposes,
cannot get rid of _port here").
For garbage collected programs this is a problem because CF objects
aren't immediately deallocated when their retain count hits zero.
They're deallocated during the next scan. So say you invalidate a
message port and release it everywhere, and then shortly thereafter
create a new local message port with the same name. If the GC hasn't
scanned the old object in the interim then you'll get an error that
the port name is already in use.
To get around this I'm allocating the message port (and it's run loop
source) using kCFAllocatorMallocZone, which causes the message port to
be deallocated immediately when released. This seems to work fine, but
I'm getting errors: "storing a non-GC object 0x1ab784 in a GC
collection, break on CFCollection_non_gc_storage_error to debug".
CFMessagePort stores all local ports in a global dictionary, which is
probably the source of this.
Is there another way to deal with this? Does this warrant filling a
radar?
Best,
Ryan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden