In one of my functions, I have a while loop with a certain case where it may need to temporarily create an object. My code looks like this:
while(c < end){
if(specialCase){
Object *myObject = [Object alloc];
//do stuff with myObject
//I tried [myObject dealloc] here, but it crashed when this method was called.
}
c++;
}
The code works fine as is but I am worried about memory leaks. I would like to know if and how I should dealloc myObject.
You NEVER call Dealloc directly.
you call Release and when retain count reaches 0 dealloc will be called on object.