1

I have uploaded an image from picker to ImageShack using Alamofire Image request and then caching that image connected with Firebase. (developing Swift & XCode updated all) I'm new using XCode Instruments, getting ContiguousArrayStorage String leak warning,

What does it mean? How Can I fix it? Is there any problem for memory allocations?

My Alamofire uploading codes here: How to save memory using AlamofireImage/ImageShack?

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Every time increase size and number of same leaks while uploading image.

** Edited: I have uploaded 340 images comes 200 KB.

enter image description here

enter image description here

Community
  • 1
  • 1
iamburak
  • 3,508
  • 4
  • 34
  • 65
  • 2
    A likely cause is a retain loop in one of your completion handlers. But it could be a bug in AF or in Cocoa (Cocoa has a number of internal leaks). It's important to keep perspective on this. You're leaking 208 bytes per upload. After 40 uploads you've leaked 8k. How many uploads do you expect before you're terminated? If it's less than several thousand, I would chalk this up to unfortunate and focus on other issues. As a rough rule, if you don't expect a to ever reach 1MB over the life of the program, it's not worth spending extensive time on. You probably won't be able to fix it anyway. – Rob Napier Apr 16 '16 at 14:50
  • As a learning exercise, this is fine to explore of course, and I encourage that if you have time. But you will likely need to to experiment a lot; removing parts of the code and retesting until you can narrow down the exact cause. It is time consuming, but can be a valuable lesson if you have time to explore it. – Rob Napier Apr 16 '16 at 14:51
  • Thanks for your interest Rob. Firstly there are less than 40 images uploaded, 8 KB leaks. And then I have tried to upload 340 images (You can see edited topic) comes 200KB leaks and 120 MB Persistent All Heap. In this balance I think that for 1 MB leaks can be 1700 images. Also I wonder that 120 MB allocation, is it logic for this status? – iamburak Apr 17 '16 at 13:04
  • I'm using same completion handler **Uploading MultipartFormData** from https://github.com/Alamofire/Alamofire also I have linked another topic for my own uploading steps. – iamburak Apr 17 '16 at 13:20
  • Are you using string interpolation by any chance? I was having leaks with `ContiguousArrayStorage` as well and after changing the string interpolation to String initialization (`String(someValue)`) made the leaks disappear. – Eendje Apr 21 '16 at 14:00
  • Can you explain much more about this case, I couldn't understand exactly. If this happen while uploading request, you can check my Alamofire codes in linked topic area. It would be great. – iamburak Apr 21 '16 at 14:21
  • I've been checking (line for line...) and so far I've found two occurrences. When using string interpolation and having the strings in an Array and accessing it with `forEach()`. It seems to happen "randomly" though. So if you want to get rid of the leaks, you could either wait for Apple to "fix" it or going through your code line by line and replacing the strings with other methods. Either way, it'll be very time consuming like Rob said. Worst thing is I have no idea what's causing this. – Eendje Apr 21 '16 at 14:56
  • In some cases I even had to use a `NSString` and cast it to a Swift String when adding a value to a dictionary. I'm not sure if it fixed the whole problem, but by doing this I got rid of most of the leak errors. – Eendje Apr 21 '16 at 16:54
  • @tobeiosdev i am also getting same issue like you, can you please tell solution if you have – Narayana Rao Routhu Oct 13 '16 at 17:58
  • @Narayana Actually pivot from using ImageShack uploading with Alamofire, but above error trigger is probably string interpolation, for example "\\(dontDo)" You can try directly assign a variable. – iamburak Oct 14 '16 at 07:17
  • @tobeiosdev thanks you for replay. you mean i should use let value = dontDo instead of let value = "\(dontDo)" – Narayana Rao Routhu Oct 14 '16 at 10:38
  • @Narayana Yes it solved many leaks for me. – iamburak Oct 14 '16 at 11:03
  • There is a fix for this in iOS 10.3 – I make my mark Apr 12 '17 at 10:23

0 Answers0