Saving Data from URLSession to disk and NSCache causes double the memory

Originator:jus0610tin
Number:rdar://37082760 Date Originated:January 31 2018
Status:Closed Resolved:
Product:iOS SDK Product Version:iOS 11.2
Classification:Duplicate of 35563956 Reproducible:Always
 
Area:
Foundation

Summary:
When a 10MB file is downloaded using URLSession and written to disk and saved to NSCache the memory goes up by 20MB and doesn't go back down, in swift.

Steps to Reproduce:
Using Swift
Download file using URLSession using URLSession.dataTask(with: URL)
Save file data to disk
Save data using NSCache

In the Attached example project, pressing the button causes the above actions to occur.

Expected Results:
Memory usage goes up by around 10MB

Actual Results:
Memory usage goes up by around 20MB

Version/Build:
Xcode 9.2 (9C40b)

Configuration:
iOS 11.2, Simulator and iPhone X

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!