performSelector may cause a leak because its selector is unknown

后端 未结 19 2203
小蘑菇
小蘑菇 2020-11-22 01:54

I\'m getting the following warning by the ARC compiler:

\"performSelector may cause a leak because its selector is unknown\".

Here\'s what

19条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 02:48

    My guess about this is this: since the selector is unknown to the compiler, ARC cannot enforce proper memory management.

    In fact, there are times when memory management is tied to the name of the method by a specific convention. Specifically, I am thinking of convenience constructors versus make methods; the former return by convention an autoreleased object; the latter a retained object. The convention is based on the names of the selector, so if the compiler does not know the selector, then it cannot enforce the proper memory management rule.

    If this is correct, I think that you can safely use your code, provided you make sure that everything is ok as to memory management (e.g., that your methods do not return objects that they allocate).

提交回复
热议问题