both methodLists and protocols are chain-table, protocols is a pointer, but methodLists is a pointer to pointer, Why?

This is an implementation detail that is fallout from how both the history of Objective-C and the ability to dynamically add methods to classes.
Specifically, if you look at the contents of the method_list entries, you'll find that the methods are broken up into sets where each set contains all the methods from a particular category on the object. I.e. if your app were to define a category on UIView with five methods (don't do that -- bad design), then you'd find those five methods tacked on to the end of the method_list in a single objc_method_list (which is why the method_list entry is pointer aligned and variable sized).
This also extends to dynamic addition of methods. There is no need to bcopy a bunch of data into a newly allocated copy of the existing method data structure. Instead, the runtime can just allocate an objc_method_list and shove it on the end of the linked list (or at the head -- implementation detail).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With