Im having problem with memory management problem, my app runs smoothly on the simulator, but it often crashes on my device.
I just want to know if there are some guidelines of when to release an object.
What i understand is
if something starts with alloc, you need to release it.
like
Code:
NSString *string = [[NSString alloc] init];
and if the object started with initxxxxx need to have autorelease
Code:
NSString *string = [[NSString initwithformat:@"123"] autorelease];
everything delcare in @synthesize, needs to be in - (void)dealloc.
I have declare an object inside a for loop, but when i tried to release it, it crashes.
What are the situation that we must release the object on?
Correct me if im wrong, thanks.
and what are the best way to code and to make sure keep everything in low memory?!
option 1:
Code:
NSString *string = [[NSString alloc] init];
self.stringIWant = string;
[release string];
option 2:
Code:
self.stringIWant = [[NSString alloc] init];