ThingWorx auto restarts due to Out of Memory when a script is run
Hi,
When we run the below script, we are facing an out of memory issue and Thingworx tomcat service restarts automatically. we have run the below script manually from composer with execute option in a batch of 25 & 50 vin's in input array, the scripts executes and prints the final array in the script logs but internally it is causing out of memory issue, Can any one please let us know what is the issue in this script and why this is creating out of memory issue becuse we do not see any errors in the logs also.
Script:
serviceName = "updateDeviceNum";
//sample input format :{ "vin": ["123456786", "456782354"]}
var inputArrayVin = inputVIN.vin;
//logger.info(myName + " inputVIN " + inputVIN);
var inputLen = inputArrayVin.length;
logger.info(myName + " inputLen " + inputLen);
var arValueUpdated = [];
var arSkipped = [];
for (var i = 0; i < inputLen; i++) {
//calling the getAsset using VIN to get deviceID
var getAssetByVINURL = "https://**********" + inputArrayVin[i];
var apiParams = {
headers: ******,
url: getAssetByVINURL,
ignoreSSLErrors: true
};
var resultFromGetAsset = Resources["ContentLoaderFunctions"].GetJSON(apiParams);
logger.debug(myName + " resultFromGetAsset response is: " + JSON.stringify(resultFromGetAsset));
//Getting deviceID from asset response
if (resultFromGetAsset.array) {
var deviceID = resultFromGetAsset.array[0].deviceId;
logger.info(myName + " deviceID: " + deviceID);
//calling getDeviceAPI to get DeviceNo
var params = {
deviceID: deviceID
};
var resultFromGetDevice = Things["TestThing"].GetDevice(params);
logger.debug(myName + " resultFromGetDevice response is: " + JSON.stringify(resultFromGetDevice));
if(resultFromGetDevice){
var serialNo = resultFromGetDevice.sn;
var thingName = "Telematic_" + deviceID;
if (Things[thingName] && Things[thingName].PCMSerialNo == "undefined") {
Things[thingName].PCMSerialNo = serialNo;
//Things[thingName].PCMSerialNo = '5678943';
updatedDevices = {
VIN: inputArrayVin[i],
deviceID: deviceID,
sn: serialNo
};
arValueUpdated.push(updatedDevices);
} else {
updatedDevices = {
VIN: inputArrayVin[i],
deviceID: deviceID,
sn: serialNo
};
arSkipped.push(updatedDevices);
}
}
else {
updatedDevices = {
VIN: inputArrayVin[i],
deviceID: deviceID
};
arSkipped.push(updatedDevices);
}
}
else {
updatedDevices = {
VIN: inputArrayVin[i]
};
arSkipped.push(updatedDevices);
}
}
logger.info(myName + " arValueUpdated " + JSON.stringify(arValueUpdated));
logger.info(myName + " arSkipped " + JSON.stringify(arSkipped));

