Good questions.

I know that this swizzling will only be happening on NSViews (since that's what 
my code operates on).  As I mentioned in the original email, my current 
implementation exchanges -dealloc with a new one, which then invokes the 
original dealloc method.  This appears to work well, but it doesn't feel as 
clean to me (though I have no quantitative evidence as to why that may be).

As for associated objects, my code was originally implemented this way, but I 
ended up switching to an NSMapTable held by a singleton so that the code would 
be Leopard-compatible.

As for the rationale behind why I need to do this, I'll just refer to my blog 
post on the matter:  
http://davedelong.com/blog/2010/10/07/fun-objective-c-dynamic-subclassing

Cheers,

Dave

On Oct 13, 2010, at 2:54 PM, Ken Thomases wrote:

> On Oct 13, 2010, at 2:44 PM, Dave DeLong wrote:
> 
>> I maintain some code that does dynamic subclassing to override an object's 
>> -dealloc method to do some extra cleanup prior to deallocation.  (And for 
>> the curious, this cleanup is not necessary when using Garbage Collection)
> 
> As mentioned, it's not safe to do isa-swizzling because KVO also does it.
> 
> Have you considered doing method swizzling on -[NSObject dealloc]?  (And 
> maybe -[NSProxy dealloc], too, I guess.)
> 
> Also, have you considered whether you really need to be doing these sorts of 
> hacks at all? ;)  For example, could you get away with 
> objc_setAssociatedObject()?
> 
> Regards,
> Ken
> 

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to