Does calling a method from within the same method create a memory leak?
-(void)doSomething
{
[self performSelector:@select开发者_StackOverflowor(doSomething) withObject:nil afterDelay:0.1];
}
Will this cause a memory leak?
(This is called recursion; when a method calls itself. EDIT: Apparently not, according to the discussion below.)
A memory leak occurs when a reference to an object in memory is removed, but the object remains in memory. As long as you are properly releasing allocated memory, a memory leak will not occur.
No, this doesn't leak. self is retained while the method is getting called, then released when the invokation finishes.
This is not a good way to create a timer, though. Use NSTimer instead: it is much more accurate and won't drift like this will.
精彩评论