objective c - iOS app exhausting memory during download of very large file -


i know variations of question have been asked in 1 form or many times on here - i've been searching these posts extensively days , think problem unique. allow me describe:

i have ios app on ipad 4 downloads large (260mb 650mb) file disk. memory usage increasing during download proportional amount of data downloaded. @ around 500mb, app receives low memory warnings, , around 650mb killed low memory.

i've repeatedly used instruments try track down allocation coming - i've ran allocations, vm allocations, leaks, memory monitor, , activity monitor multiple times. i've taken many heapshots memory increases. instruments has never shown large amounts of allocations coming app! memory remains flat. leaks doesn't report anything.

instead i've been relying on set of functions asking kernel memory usage, found on thread here:

   vm_size_t usedmemory(void) {     struct task_basic_info info;     mach_msg_type_number_t size = sizeof(info);     kern_return_t kerr = task_info(mach_task_self(), task_basic_info, (task_info_t)&info, &size);     return (kerr == kern_success) ? info.resident_size : 0; // size in bytes }  vm_size_t freememory(void) {     mach_port_t host_port = mach_host_self();     mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);     vm_size_t pagesize;     vm_statistics_data_t vm_stat;      host_page_size(host_port, &pagesize);     (void) host_statistics(host_port, host_vm_info, (host_info_t)&vm_stat, &host_size);     return vm_stat.free_count * pagesize; }  void logmemusage(void) {     // compute memory usage , log if different >= 100k     static long prevmemusage = 0;     long curmemusage = usedmemory();     long memusagediff = curmemusage - prevmemusage;      // if (memusagediff > 100000 || memusagediff < -100000) {     prevmemusage = curmemusage;     //nslog(@"memory used %7.1f (%+5.0f), free %7.1f kb", curmemusage/1000.0f, memusagediff///1000.0f, freememory()/1000.0f);     printf("memory used %7.1f (%+5.0f), free %7.1f kb\n", curmemusage/1000.0f, memusagediff/1000.0f, freememory()/1000.0f);      //} } 

using has allowed me see something consuming memory in download loop. using requestqueue download along following method:

- (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data {     if (_filepath && _filepath.length)     {         if (_filehandle == nil)         {             [[nsfilemanager defaultmanager] createfileatpath:_filepath contents:nil attributes:nil];             self.filehandle = [nsfilehandle filehandleforupdatingatpath:_filepath];             _byteswritten = _rangestart;         }          [_filehandle writedata:data];         _byteswritten += [data length];         nsinteger totalbytes = max(0, _responsereceived.expectedcontentlength) + _rangestart;          if (_downloadprogresshandler)         {             _downloadprogresshandler(_userdata, _userdata2, (float)_byteswritten / (float)totalbytes, _byteswritten, totalbytes);         }     } } 

even if comment out [_filehandle writedata:data] call, still observe memory increasing! i've double-checked i'm closing file handle , setting nil when done, memory growth happening during download.

note: project using arc.

i'm out of things try @ point. not writing data @ file still causes memory grow. disabling uistatusbar shows download progress doesn't help. can't see in instruments. going try using nsoutputstream write file instead, i'm doubtful not writing data @ still causes memory growth.

i tried using nsurlcache , clearing cache when low memory warning received. tried assigning nil data in didreceivedata method, didn't change anything. experimented changing many strong pointers possible weak, resulted in selectors being called on deallocated instances.

any suggestions welcome @ point.

the fact you're not seeing in instruments suggests have difference between release , debug configurations significant. receive memory warnings under instruments?

edit scheme, select "profile" options , select build configuration "debug." see if matches you're seeing when use "run". if so, there can use instruments track down.

it's long-shot, 1 thing verify haven't turned on nszombies accident. if did, see kind of behavior. go scheme , check "run" options. on diagnostics pane , make sure nothing selected.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -