objective c - UIImagePickerController terminated due to Memory Pressure -


i have uiviewcontroller has :

@property uiimagepickercontroller* mainpicker; 

and button, i'm presenting mainpicker :

- (ibaction)takephoto:(uibutton *)sender { // take photo.      if(![uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypecamera])     {     // no camera available, show alert.          uialertview* newalert = [[uialertview alloc] initwithtitle:@"warning"         message:@"camera not available."          delegate:self          cancelbuttontitle:@"ok"          otherbuttontitles:nil];          [newalert show];          return;     }      if(mainpicker == nil)     {         mainpicker = [[uiimagepickercontroller alloc]init];          mainpicker.delegate = self;         mainpicker.allowsediting = yes;  //i've tried without line, didn't affect @ all.         mainpicker.sourcetype = uiimagepickercontrollersourcetypecamera;     }      [self presentviewcontroller:mainpicker animated:yes completion:nil]; } 

the first problem ;

snapshotting view has not been rendered results in empty snapshot.  ensure view has been rendered @ least once before snapshotting or snapshot after screen updates. 

also, whenever view controller presented, there @ least 2 memory warnings.

after take photo, gets worse. it's literally spamming "received memory warning.".

here instrument screenshot, hope help.

enter image description here

the memory 4 mb @ beginning. after taking photo, goes 10 mb. while dismissing, i'm saving uiimage, it's 30 mb after dismissal. (that peak of memory caused writetofile:. also, leak there 600 bytes only).

currently, i'm testing on iphone 5s, ios 7.

i've tried enabling zombies, dispatching picker after while, allowing/disallowing editing, etc. none of them worked. also, i'm not trying present picker view instantly after loading view controller.

additional note, i've used functions in answer, , here logs;

memory used  9588.7 (+9589), free 32063.5 kb memory used 10281.0 ( +692), free 18448.4 kb 

watching memory usage in ios

isn't bit weird see 32 mb free memory in device, whilst instruments telling story?

here few explanations solve problem.

first of all, zombies diagnostic tool meant debug crashes in memory freed being accessed. doesn't seem problem here , zombies tool useless particular problem.

second, screenshot have provided showing leaks instruments. elements see in list objects program has allocated , forgotten without releasing them beforehand. means not have single remaining pointer towards memory instruments knows about. fixing these leaks first step towards fixing memory warnings.

third, fixing leaks won't enough fix memory warning problems. these warnings indicate using memory ios's liking. considering leaks account mere 600 bytes, problem seems abandoned memory. abandoned memory memory have allocated, , towards still have live references though won't ever used again application.

in order in fixing problems, here relevant documentation fix both memory leaks , abandoned memory using instruments :
https://developer.apple.com/library/mac/recipes/instruments_help_articles/findingmemoryleaksinyourapp/findingmemoryleaksinyourapp.html#//apple_ref/doc/uid/tp40012965-ch32-sw1
https://developer.apple.com/library/mac/recipes/instruments_help_articles/findingabandonedmemory/findingabandonedmemory.html

also, here useful blog post abandoned memory : http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -