Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using objc_disposeClassPair()

There's an undocumented function in the runtime API, which appears (on the basis of a few toy programs) to do what its name suggests it does:

OBJC_EXPORT void objc_disposeClassPair(Class cls) 
     AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;

However, detailed information is fairly thin on the ground. So this is more a cluster of related questions than a single one:

  • Are there any good articles / blog posts around that look at it, or does anyone have any experience of using it (A quick google suggests that the PyObjC developers at least looked into using it at one point)?
  • Are disposed-of classes completely deallocated (would an application that frequently created and deleted classes leak memory?)
  • Are there any gotchas worth keeping in mind beyond the usual about undocumented APIs?
  • Where is it (/might it be) used by Apple? NSBundle unloading? KVO?
like image 539
Chris Devereux Avatar asked Nov 04 '22 21:11

Chris Devereux


1 Answers

Are disposed-of classes completely deallocated (would an application that frequently created and deleted classes leak memory?)

Yes, they will be completely deallocated. If you look at the cycle function in http://www.opensource.apple.com/source/objc4/objc4-437/test/classpair.m, you will find that it both allocates and deallocates multiple classes. The main implementation below runs that function 100 times, and checks for leaks, which indicates that they wouldn't release an implementation which leaked significantly. If you want to find out more, you should look through the code in http://www.opensource.apple.com/source/objc4/objc4-437/runtime/. You can probably find apple's actual code for both functions in there somewhere, as well as where it is used.

like image 158
ughoavgfhw Avatar answered Nov 12 '22 19:11

ughoavgfhw