Skip to main content
Inspiring
June 7, 2020
Answered

Will memory usage change between field level and document level?

  • June 7, 2020
  • 3 replies
  • 1063 views

Does writing all the code in each field, or writing a document-level function and writing it, change the overall processing speed of the document?

 

Does (1) and (2) below change the overall document processing speed? For example, suppose there are about 20 fields that use the same calculation. And suppose it's a bit longer code.

 

(1) Write the same code in all fields.
(2) Write a document level function and use it.

 

Obviously, (2) is the safest and easiest way to write code.

 

Is there any difference between (1) and (2) above?  Of particular interest is how PDF JavaScript uses memory.  I've heard that generally global functions use a lot of memory, so it's better not to use too much.

This topic has been closed for replies.
Correct answer Thom Parker

I believe you read that uses of the "Global" object should be limited, because it can cause memory usage issues. This has nothing to do with functions.

 

Functions and JavaScript code in general have no greater or lessor affect on memory that depends on location. Now, if you put the same code in several different fields, this does take up more memory, but the amount is trival.

The actions the scripts perform however, can have a huge effect on memory. The JavaScript engine does not clean up unused objects quickly.  So if you write code that creates lots of new objects (variables) it can cause problems. 

3 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
June 7, 2020

I believe you read that uses of the "Global" object should be limited, because it can cause memory usage issues. This has nothing to do with functions.

 

Functions and JavaScript code in general have no greater or lessor affect on memory that depends on location. Now, if you put the same code in several different fields, this does take up more memory, but the amount is trival.

The actions the scripts perform however, can have a huge effect on memory. The JavaScript engine does not clean up unused objects quickly.  So if you write code that creates lots of new objects (variables) it can cause problems. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
June 8, 2020

Thank you very much. Your explanation was all I wanted to know. I learned a lot.

try67
Community Expert
Community Expert
June 7, 2020

I don't believe there's any difference at all in memory consumption, and of course not in "safety", whatever that means.

It's much better to use a doc-level script with a function that is called from the individual fields because if you need to edit the code you can just do it once and don't need to go field by field to edit it.

Inspiring
June 8, 2020

Thank you very much. I was relieved to hear it.

Bernd Alheit
Community Expert
Community Expert
June 7, 2020

"I've heard that generally global functions use a lot of memory, so it's better not to use too much."

Where have you heard or read this?

Inspiring
June 7, 2020

I'm sorry, but I don't remember where the page actually was. I read it on the page that describes JavaScript.