Wrapping services into anonymous function
Is there any benefit of wrapping whole service into anonymous function?
eg.
(function() {
const someText = 'test';
logger.info(someText);
})();
const result = function() {
const someText = 'test';
return someText;
}();
I'm not sure how local variables (service scope) are managed after the service execution completes/fails. Are those variables continue to exist, even if we cannot access them? If yes, it would make sense to wrap whole service into anonymous function, so we are sure they are destroyed after function returns.
I saw this approach few times and it makes sense for me when the service returns value - we can use return statement in any place in the service, but I'm not sure about memory/security benefits.
Is there any documentation on how ThingWorx manages the cleanup and disposal of resources associated with the service execution?

