Stavash basically covered that whether you release it depends on whether the method returned a retaining instance or not.
However, you shouldn't really ever need to know what a method does in order to use memory management correctly. Cocoa MRC memory management follows rules on what methods do based on the name of the method. According to the rules, methods whose names start with alloc
, retain
, new
, copy
, or mutableCopy
return a retained instance, and the caller are responsible for releasing it. Methods with all other names return a non-retained instance, and the caller should not release it.
So, assuming (of course, that's a big assumption) that initForStringTheory
follows the rules properly, it should not return a retaining instance (that does not mean it is necessarily autorelease
d; it may be retained by something else and simply returned directly to you).
Another part of the problem is that it is highly unconventional to have a class method named init...
. Generally, instance methods starting with init
are constructors, which are run immediately on the result of an alloc
which created the instance. So what the hell does a class method named init...
do? Also, by convention there is a special rule for init
methods, that it "consumes" the retained instance returned by alloc
, and returns a (not necessarily the same) retained instance. But how would that apply to this case, where it is called on a class? Would it "consume" a retain count on the class object (which does nothing), and then return a retained instance? Nobody knows.
So in conclusion, this code really needs to be re-written. Definitely do not have class methods named init...
. And make sure that all the methods you write have memory management behaviors that correctly follow the rules, based on their names.