• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dynamically subclassing an observed object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamically subclassing an observed object


  • Subject: Re: Dynamically subclassing an observed object
  • From: Dave DeLong <email@hidden>
  • Date: Wed, 13 Oct 2010 15:52:17 -0600

Yeah, thanks for this.  I've been over Mike's code, and he gets around this issue by using class_setSuperclass(), which the documentation says should not be used.

How would using a CFDictionary with custom callbacks make things any better?  In order to find things in the dictionary, things are binned by their hash.  Presumably when a CFDictionary needs to grow, it's going to rehash all of the keys (using CFHash() or -hash), but if some of those keys point to deallocated memory (ie, the user is not using Garbage Collection), then I'm liable to crash.  This is what necessitated the auto-cleanup subclassing in the first place.  Would a CFMutableDictionaryRef allow me to get around this issue?

Dave

On Oct 13, 2010, at 3:47 PM, Kyle Sluder wrote:

> On Wed, Oct 13, 2010 at 2:02 PM, Dave DeLong <email@hidden> wrote:
>> 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
>
> Funny enough, it sounds like the blog post I linked you to (and the
> ones following it) that talks about MAZeroingWeakRef does precisely
> what you need: http://www.mikeash.com/pyblog/introducing-mazeroingweakref.html
>
> You can find Mike's code on github.
>
> Alternatively, you could go back to the NSMapTable approach, but
> instead of using an NSMapTable use a CFDictionary with custom
> callbacks.
>
> --Kyle Sluder

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

_______________________________________________

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

  • Follow-Ups:
    • Re: Dynamically subclassing an observed object
      • From: Dave DeLong <email@hidden>
References: 
 >Dynamically subclassing an observed object (From: Dave DeLong <email@hidden>)
 >Re: Dynamically subclassing an observed object (From: Ken Thomases <email@hidden>)
 >Re: Dynamically subclassing an observed object (From: Dave DeLong <email@hidden>)
 >Re: Dynamically subclassing an observed object (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Dynamically subclassing an observed object
  • Next by Date: Re: The dreaded "UITableView won't refresh" problem.
  • Previous by thread: Re: Dynamically subclassing an observed object
  • Next by thread: Re: Dynamically subclassing an observed object
  • Index(es):
    • Date
    • Thread