title: iOS Background Transfer - com.apple.nsurlsessiond folder full of tmp files
body: <p>We've written a media application that allows you to get a list of latest videos as json list using BACKGROUND FETCH </p>
  
  <p>then it uses BACKGROUND TRANSFER to tell iOS to download the video one by one and go back to sleep and to wake the app when its done.</p>
  
  <p>It does all that but we've noticed that Space Usage is growing and growing. </p>
  
  <p>We added code to clear all downloaded videos but space usage stayed hi in settings.</p>
  
  <p>We downloaded the app folders using Xcode > Organizer> Devices and found the BACKGROUND TRANSFER tmp folder was dull of tmp files.</p>
  
  <p>Shouldn't these be getting cleared out</p>
  
  <p>This is in general the code I use.
  I think the main is I attach multiple DownloadTask(can be up to 30) to one background session. files vary in size from movies to pdfs.</p>
  
  <pre><code>NSURLSession * backgroundSession_ = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:identifier];
  
  
  backgroundSession_ = [NSURLSession sessionWithConfiguration:urlSessionConfigurationBACKGROUND_
                                                     delegate:self
                                                delegateQueue:[NSOperationQueue mainQueue]];
  
  NSOperationQueue *mainQueue_ = [NSOperationQueue mainQueue];
  
  
  
  NSURLSessionDownloadTask * downloadTask_ = [backgroundSession_ downloadTaskWithURL:url_];
  
  downloadStarted_ = TRUE;
  [downloadTask_ resume];
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/022sV.png" alt="enter image description here"></p>