{ "id": "174063", "key": "AC-6348", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": null, "resolutiondate": null, "created": "2019-08-26T13:13:33.000+0000", "labels": [], "versions": [], "issuelinks": [], "assignee": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2019-11-04T20:12:11.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "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.\r\n\r\nHere is the code:\r\n{code:java}\r\nfunction importJsonFiles(entityName){\r\n\r\nvar totQty = 0;\r\n\r\nvar fileIndex = 1;\r\n\r\nvar jsonFile = null;\r\n\r\nvar entityList = null;\r\n\r\nwhile(Ti.Filesystem.getFile(FileManager.getCatalogDirPath() + \"/jsonData\", entityName + \"_\" + fileIndex + \".json\").exists()){\r\n\r\njsonFile = Ti.Filesystem.getFile(FileManager.getCatalogDirPath() + \"/jsonData\", entityName + \"_\" + fileIndex + \".json\");\r\n\r\nentityList = JSON.parse(jsonFile.read().text);\r\n\r\nTi.API.info(\"Parsed file: \" + entityName + \"_\" + fileIndex + \".json\");\r\n\r\ntotQty += entityList.length;\r\n\r\nif(entityName == 'itemprice')\r\n\r\nDBManager.priceJSON_to_db(entityList);\r\n\r\nelse if(entityName == 'customer')\r\n\r\nDBManager.customerJSON_to_db(entityList);\r\n\r\nelse if(entityName == 'userprofilecustomer'){\r\n\r\nvar emptyTable = (fileIndex == 1 ? true : false);\r\n\r\nDBManager.userProfileCustomerBrandJSON_to_db(entityList, emptyTable);\r\n\r\n}\r\n\r\nfileIndex++;\r\n\r\njsonFile = null;\r\n\r\nentityList = null;\r\n\r\n}\r\n\r\nif(entityName == 'itemprice')\r\n\r\npriceSize = totQty;\r\n\r\nelse if(entityName == 'customer')\r\n\r\ncustomerSize = totQty;\r\n\r\n}\r\n{code}\r\n\r\nDBManager methods just loop the entitylist writing data to a sql lite database in one transaction.\r\n\r\nWe 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.\r\nIs there a way to call garbage collection at every loop and clear memory allocated by each imported json file?\r\nWe 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.", "attachment": [], "flagged": false, "summary": "Memory allocation problem while reading consecutive files", "creator": { "name": "portal@quix.it", "key": "portal@quix.it", "displayName": "Portal", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "portal@quix.it", "key": "portal@quix.it", "displayName": "Portal", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "451117", "author": { "name": "portal@quix.it", "key": "portal@quix.it", "displayName": "Portal", "active": true, "timeZone": "America/Los_Angeles" }, "body": "any news on this issue?\r\n\r\nThanks", "updateAuthor": { "name": "portal@quix.it", "key": "portal@quix.it", "displayName": "Portal", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-09-05T12:40:05.000+0000", "updated": "2019-09-05T12:40:05.000+0000" }, { "id": "451514", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "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.", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2019-09-19T21:19:34.000+0000", "updated": "2019-09-19T21:19:34.000+0000" }, { "id": "451526", "author": { "name": "portal@quix.it", "key": "portal@quix.it", "displayName": "Portal", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Hi, \r\nif 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?\r\nThanks.", "updateAuthor": { "name": "portal@quix.it", "key": "portal@quix.it", "displayName": "Portal", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-09-20T07:04:01.000+0000", "updated": "2019-09-20T07:04:01.000+0000" }, { "id": "452463", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "Hello [~portal@quix.it], please provide a standalone sample project of code for us to test the issue in our end. Thanks.", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2019-11-04T20:12:11.000+0000", "updated": "2019-11-04T20:12:11.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }