3

I've got a method which uses swift's String(contentsOf: ... function to pull data off a website asynchronously several times in a row. Using the SwiftSoup library, I'm able to parse data from the HTML. This data is then stored into an array of struct instances. The struct contains 3 Strings, 2 Ints, 1 Bool and 1 array of strings

It works great, but something what I've noticed is that whilst profiling my app's memory use, is that every time I call this method, persistent RAM usage increases by around 1.5MiB every time.

My question is, is this normal behavior? If not, how can I force my app to release unused variables or whatever to memory?

Leaks check in the Instruments app

Do note that the peaks shown in the screenshot are from a different method which is called when changing to a different view controller, so they may be ignored.

wp78de
  • 18,207
  • 7
  • 43
  • 71
Rstew
  • 585
  • 2
  • 9
  • 21
  • 4
    I wouldn't advise `String(contentsOf:)` (it's synchronous, non-cancelable, doesn't perform any error reporting, etc.), but it shouldn't be the source of the problem. I'd suggest focusing on some reasonably high-level object that looks suspicious (e.g. does it make sense that you have 38k persistent `TextNode` objects and no transient ones?) and identify why those aren't getting released. Look at _where_ they were instantiated and see if it makes sense that they're not released. https://stackoverflow.com/a/30993476/1271826. This smells like strong ref cycle. Not enough here to diagnose, tho. – Rob Jun 18 '17 at 22:35

0 Answers0