Copy link to clipboard
Copied
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.
1 Correct answer
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 unuse
...Copy link to clipboard
Copied
"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?
Copy link to clipboard
Copied
I'm sorry, but I don't remember where the page actually was. I read it on the page that describes JavaScript.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thank you very much. I was relieved to hear it.
Copy link to clipboard
Copied
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.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thank you very much. Your explanation was all I wanted to know. I learned a lot.

