title: How to clear cache of NSURLSession when a large file is downloading?
body: <p>I am using NSURLSession to download a large video file in background. In this iOS application I implemented pause, resume and stop downloading feature.</p>
  
  <p>Here is my code :</p>
  
  <p>in .h</p>
  
  <pre><code>@property (nonatomic, strong) NSURLSessionDownloadTask *downloadTask; 
  @property (nonatomic, strong) NSURLSession *session;
  </code></pre>
  
  <p>in .m</p>
  
  <pre><code>NSURLSessionConfiguration *sessionConfiguration;
  float ver = [[[UIDevice currentDevice] systemVersion] floatValue];
  
  if(ver &gt;= 8)
  {
      sessionConfiguration =  [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"sessionID"];
  }
  else
  {
      sessionConfiguration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"sessionID"];
  }
  
  sessionConfiguration.HTTPMaximumConnectionsPerHost = 1;
  self.session = [NSURLSession sessionWithConfiguration:sessionConfiguration
                                                   delegate:self
                                                   delegateQueue:nil];
  </code></pre>
  
  <p>For stop downloading I am using this method:</p>
  
  <pre><code>- (void)stopDownloading:(id)sender {        
      // Cancel the task.
      [self.fdi.downloadTask cancel];        
  }
  </code></pre>
  
  <p>It works quite well with a large amount of files, but there is an inconvenience. When I stop downloading then Memory which is used in downloading is not released so the application size is continuously for stopped downloading tasks. </p>