Swift memory usage

I imported swiftSoup to crawl something simple. The code is less than 40 lines.

It ran fine on my raspberry pi 4.

But it kept crashing on my pi zero 2.

I really want to know how much ram swift needs?

That depends entirely on what the code does.


I really want to know how much ram swift needs?

Swift’s runtime is quite lightweight so there isn’t some specific value where you can say “all Swift programs need X amount of memory just to start up”. Which brings you back to Avi’s answer…

Are you sure it’s crashing because it ran out of memory? There are lots of other reasons why code can run on one device and fail on another.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

SwiftSoup is an HTML parser/scraper similar to the Python Beautiful Soup library. Looking at the readme file, it seems that it parses the entire HTML document you wish to scrape into memory. It's probably fair to say that its memory profile heavily depends on the complexity of the HTML document it is trying to scrape.

Oh. Thanks.
Didn't think about that. This makes sense.

I agree it's not very relevant in this case, but I have measured this :slightly_smiling_face: adding Swift to an otherwise-empty (just sleep()s in main) C process on my Darwin system adds 128kB of total dirty memory, of which 16kB is heap memory coming from 28 additional allocations.

This will vary depending on system libraries, symbol ordering, memory allocator, and other factors of course. My particular system is likely measuring a bit on the high side at the moment for unrelated reasons.

(edited to correct numbers slightly, I forgot I had edited my test program, and reverting the edits reduced it from 176kB to 128kB and from 37 allocations to 28)