I am working on reducing memory footprint (RAM) of an iOS app. One potential area is to reduce the number of languages supported by our app as there will be multiple of Localizable.strings files.
My colleague has mentioned that all strings files are loaded at once (in RAM) and hence, we need to reduce the number of language supported.
I have dug deeper into NSLocalizedString and looks like only current locale localised string should be loaded into the memory.
If we have 100s of Localizable.strings files, then only current locale localised string file will be loaded. And they are loaded into heap segment of the memory.
However, if I explicitly calls the following (hypothetically), then the requested string files of that language will be loaded into NSMutuableDictionary (heap segment):
let lanArr = ["en", "hi", "es", "ar", "el", "ja", "tr", "zh-Hant"]
var index = 0
let path = Bundle.main.path(forResource: lanArr[index], ofType: "lproj")
let bundle = Bundle(path: path!)
let str = NSLocalizedString("abhi", tableName: nil, bundle: bundle!, value: "", comment: "")
display(str)
Is my understanding correct?
So I don't have to be worried about too many languages supported (too many strings files) as only current localised string file is loaded into RAM?
Let's say I do explicitly call NSLocalizedString() for specific language, then old NSMutuableDictionary (which has string file content) won't be deallocated?
If so, then we don't have to be worried about number of languages, as space complexity will be always O(1) w.r.t number of languages.