web stats
What are the best practices regarding javascript and memory? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Development

Thread Tools Display Modes
Old 11-15-2018, 03:08 AM
aceinc aceinc is offline
OBX.1 Kenobi
Join Date: Sep 2013
Posts: 41
aceinc is on a distinguished road
Default What are the best practices regarding javascript and memory?

I have two scripts both accessing Oracle DBs. They work, but over time (weeks) they seem to fail. Restarting Mirth seems to correct the issue.

In other languages there are best practices for house cleaning to prevent memory leaks. Are there any specific actions I should be taking in regards to variables and objects when I am done with them in Mirth/Javascript?
Reply With Quote
Old 12-17-2018, 01:18 PM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,159
agermano is on a distinguished road

If they are java objects, you will want to perform any clean-up operations that you would do in java (such as closing any closeable objects.)

For the most part, mirth doesn't hang on to object references created in user scripts for too long. Exceptions would be things placed in the global maps.

If you have a variable containing a reference to a rather large object (maybe the entire contents of a file or something) you can set that variable to a different value (null or undefined if you are finished with the variable.) That will make the large object immediately eligible for garbage collection instead of waiting for the variable to go out of scope.

Also, because of the way mirth runs filters and transformers in the same javascript context, any objects assigned to variables in the global context (rather than to variables declared with the var keyword) in the filter will carry through to the transformer of the same connector rather than falling out of scope when the filter finishes (this can also be used to your advantage if you want to pass values between the filter and transformer without having to store them in a mirth map.)

Last edited by agermano; 12-17-2018 at 01:24 PM.
Reply With Quote

best practices, javascript, memory

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 09:49 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation