[AC-6348] Memory allocation problem while reading consecutive files
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | n/a |
Reporter | Portal |
Assignee | Shak Hossain |
Created | 2019-08-26T13:13:33.000+0000 |
Updated | 2019-11-04T20:12:11.000+0000 |
Description
In our application we syncronize data with a rest api that returns a zip containing a variable number of json files. Inspecting memory allocation using xcode instruments, we found out that memory allocation constantly grows until the app crashes cause of a out of memory error.
Here is the code:
function importJsonFiles(entityName){
var totQty = 0;
var fileIndex = 1;
var jsonFile = null;
var entityList = null;
while(Ti.Filesystem.getFile(FileManager.getCatalogDirPath() + "/jsonData", entityName + "_" + fileIndex + ".json").exists()){
jsonFile = Ti.Filesystem.getFile(FileManager.getCatalogDirPath() + "/jsonData", entityName + "_" + fileIndex + ".json");
entityList = JSON.parse(jsonFile.read().text);
Ti.API.info("Parsed file: " + entityName + "_" + fileIndex + ".json");
totQty += entityList.length;
if(entityName == 'itemprice')
DBManager.priceJSON_to_db(entityList);
else if(entityName == 'customer')
DBManager.customerJSON_to_db(entityList);
else if(entityName == 'userprofilecustomer'){
var emptyTable = (fileIndex == 1 ? true : false);
DBManager.userProfileCustomerBrandJSON_to_db(entityList, emptyTable);
}
fileIndex++;
jsonFile = null;
entityList = null;
}
if(entityName == 'itemprice')
priceSize = totQty;
else if(entityName == 'customer')
customerSize = totQty;
}
DBManager methods just loop the entitylist writing data to a sql lite database in one transaction.
We tried to follow guidelines described here https://wiki.appcelerator.org/display/guides2/Managing+Memory+and+Finding+Leaks but it looks like there is no way to get back allocated memory.
Is there a way to call garbage collection at every loop and clear memory allocated by each imported json file?
We are using SDK 7.4.1, at the moment we can't test with SDK from 8.0.0 cause of an error related to webview and angular routing.
any news on this issue? Thanks
Hello, Did you tied the "JavaScript garbage collection" https://wiki.appcelerator.org/display/guides2/Managing+Memory+and+Finding+Leaks#ManagingMemoryandFindingLeaks-JavaScriptgarbagecollection in the link there. Let us know what have you tried with sample code for garbage memory collection. Thanks.
Hi, if you look at the provided example you'll se that in every while loop we set to null the local variable references as stated in the "JavaScript garbage collection" section. Anyway memory constantly grows, it looks like garbage collection is not being called. Maybe is there some memory leak when using json parse or file read? Thanks.
Hello [~portal@quix.it], please provide a standalone sample project of code for us to test the issue in our end. Thanks.