iphone - Detecting C leak using Instruments (Leaks) -
i wrote test code check how use instrument (leaks). have created single view application , on button click have loaded new view this...
- (ibaction)btn_clkd:(id)sender { new_file *new = [[new_file alloc] init]; if (new) { [self.navigationcontroller pushviewcontroller:new animated:yes]; new = nil; } }
in new_file viewdidload method, have create leak below...
- (void)viewdidload { [super viewdidload]; // additional setup after loading view nib. char *c_mem = (char*) malloc(10000000); strcpy(c_mem, "testing"); // free(c_mem); }
even i'm using arc, memory allocated plain c malloc, , have not freed memory after used, though have popped , loaded again , again new view, instrument(leaks) not detecting leak in code... reason, checking correctly?
thanx
given view controller deallocated (please verify), eventually leaks detect c_mem
pointer leaks.
instruments may not find immediately - due algorithm uses detect leaks.
the algorithm searching unreferenced variables looking pointers point heap. if happens there arbitrary variable, p, value happens value of c_mem
- instruments thinks pointer c_mem
still referenced p -- though p may contain arbitrary data , not referencing c_mem
.
note instruments leak detecting algorithm more sophisticated, , may change , improved.
in order find leaks, run special code - unit tests - in loop. if used memory not grow in time, good. can use "snapshot" feature of leaks, , "mark generation" feature of allocations check current state of heap.
Comments
Post a Comment