Итак, у меня есть это приложение, которое берет 2x9500 строк данных из 2 текстовых файлов и анализирует их в области.
Для этой цели я перебираю эти строки следующим образом:
func parseToRealm() {
// each of these files have 9500+ lines of data
// (basically dictionaries with word definitions)
let graphicsFileContents = readFile_Graphics()
let dictFileContents = readFile_Dict()
// check if counts of two source files match
if (graphicsFileContents.count == dictFileContents.count && graphicsFileContents.count > 1 && dictFileContents.count > 1) {
var i = 0
// make empty array of characters
var characterArr = [Characters()]
// loop through two files to get all chars
for jsonString in graphicsFileContents {
// parse data from string into json
let dataFromString = jsonString.data(using: .utf8)
let singleCharJson = try? JSON(data: dataFromString!)
// parse stuff from file1
// ... deleted lines for legal reasons
// DICT information
let dictDataFromString = dictFileContents[i].data(using: .utf8)
let singleDictJson = try? JSON(data: dictDataFromString!)
// parse stuff from that dictionary
// ... deleted lines for legal reasons
characterArr.append(Character)
// Every x characters, write them into DB
if (i % 150 == 0 || i == graphicsFileContents.count){
realmActions.writeCharsToRealm(characterArr: characterArr)
print("Writing \(i)-\(i + 150)")
// reset array to safe memory
characterArr = [Characters()]
}
i+=1
} // end loop file contents
}else{
print ("two files have different counts of lines. aborting...")
}
}
Объясняя приведенный выше код:
- сначала я помещаю все строки текстовых файлов в переменную
- , а затем перебираю каждую строку
- Я анализирую каждую строку в массив
- после разбора 150 строк в этом массиве, я отправляю их в область
- повторяю до тех пор, пока не выполню
Проблема:
- Я использую много памяти.
- Я начинаю с 40, затем загружаю файлы.
- Затем он переходит на 80ish
- Как только массивы заполняются, они постоянно увеличиваются до 399 МБ.
- Sidenote: перед выполнением шагов по 150 элементов / раз приложение ломается на 650 МБ памяти на моем iphone 6
- Это займет не менее двух минут.
Нужная мне помощь:
- Самое главное: где я могу найтиe где / по каким переменным используется память?
- Secondary: как сделать это быстрее?
Снимок экрана использования памяти: ![400mb memory usage. what the...](https://i.stack.imgur.com/r1wc3.png)
Редактировать: Отображение результатов теста.Кажется, у меня много выделений ... ![Test results](https://i.stack.imgur.com/5zZUl.png)