• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

app.doScript memory leak

Community Beginner ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

in my scripts i use the app.doScript method which allows me to have a single undo for the entire script.

In a persistent engine i noticed (using the $.summary) that every time a script is running,  the functions count increase.

Even after a double $.gc() the memory is not released.

 

 

#targetengine 'test'

function test(v) {
    return v + 1;
}

app.doScript(test);

$.gc();
$.gc();

alert($.summary());

 

 

there's a way to prevent this sort of memory leak? 

TOPICS
Performance , Scripting

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Jan 22, 2020 Jan 22, 2020

Something like this seems to avoid the problem:

#targetengine test
var test;
!test && test = function(v) {
    return v + 1;
}

app.doScript(test);

$.gc();
$.gc();

alert($.summary());

Votes

Translate

Translate
Community Expert ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Hi Roberto,

did you test different undo modes?

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#UndoModes.html

 

What's your version of InDesign and operating system?

 

Regards,
Uwe Laubender

( ACP )

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Hi Uwe,

 

I'm on Macbook Pro, with High Sierra.

I tried all the 4 undo modes, in InDesign CC2019 and CC2020.

Same results. Functions count increase every time, garbage collector seems to fail to release the memory used, even with simple function that does not involve the InDesign DOM.

 

thank you, Roberto

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

I notice that if you do not use a custom target engine, and use Main instead, the function count doesn't increase.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

i know.

But I have to use a persistent engine, loading tons of other functions, create menu, menuaction, etc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Something like this seems to avoid the problem:

#targetengine test
var test;
!test && test = function(v) {
    return v + 1;
}

app.doScript(test);

$.gc();
$.gc();

alert($.summary());

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

LATEST

yes!! .... and (maybe) no..

I thought the problem was the app.doScript() but is the redeclaration of the test function.

 

But leaving the redeclaration and calling test() (without the app.doScript) the functions count does not increase. Very strange.

 

thank you, Roberto

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

When you run the script, a new function with the same name is defined.

With your call of doScript, the ExtendScript engine passes a reference to that function to InDesign.

Apparently InDesign never releases that reference, so the persistent target engine has to keep it around. For example other places where such references are passed are event handlers / listeners, and there you want to stick them around for long.

 

There are multiple solutions:

invoke the function by name, passing a script code instead of the function object.

app.doScript("test()");

Define the function once, and in later invokations refer to the existing function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines