NSURLSession leaks it's objects under proxy environment

Hi,


We are facing a memory leak issue caused by NSURLSession when it downloads data with https protocol via proxy server. Minimum code like below reproduces large amount of memory leak on a few call of startDownload. This happens on device or simulator with iOS10.2. iOS9.3 causes the similar memory leaks, but the leak objects are NetworkProxy related ones only.


- (void)startDownload {
    NSURLSessionConfiguration *urlSessionCfg = [NSURLSessionConfiguration defaultSessionConfiguration];
    _session = [NSURLSession sessionWithConfiguration:urlSessionCfg delegate:self delegateQueue:nil];
    NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.apple.com"]
                                         cachePolicy:NSURLRequestReloadIgnoringCacheData
                                     timeoutInterval:100];
    NSURLSessionDataTask *task = [_session dataTaskWithRequest:req];
    [task resume];
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
didCompleteWithError:(nullable NSError *)error {
    [_session invalidateAndCancel];
    _session = nil;
}

We need private session objects, not shared one, changing session config and delegate.


What is the status of this issue? Are there any workarounds to avoid this leak?

Thank you,

Replies

What is the status of this issue?

Did you file a bug about it? If so, what’s the bug number?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi eskimo,


I have not filed a bug report yet.


I would like to confirm if our usage of NSURLSession is correct or not first, including environmental circumstance.

So, I amend my question, is our usage correct? Do I need to file a bug report?


Thanks and regards,

It’s hard to imagine any use of NSURLSession that would cause leaks in the proxy case but not in the direct case (-: so, please do file a bug report. It help if you included the test project that reproduces this issue and an Instruments trace of the leak.

If you post your bug number here I’ll take a look.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi eskimo,


I have filed a bug report. The report number is

30255549

Sample project and instrument trace file are included as you suggested.

Please take a look at the report.


Thanks and regards,

I have filed a bug report. The report number is 30255549

Thanks. Much appreciated.

All of these leaks are deep within NSURLSession. Based on the type and backtrace of the leaks themselves, I don’t think there’s anything you’re doing to trigger the leaks, or anything you can do to avoid them. You will, alas, just have to wait for NSURLSession engineering to fix them.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"