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

[Q] Can I somehow facilitate memory management / garbage collection in tight loops?

Explorer ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

Hi,

 

I'm running into memory problems and am looking for some advice.

 

I run a double tight for-loop in which I draw thousands of shapes. While the for-loops are active I notice that memory is being consumed quickly. When I stop the drawing process and with the resulting Illustrator file still open, I see memory usage fall significantly, back to normal levels. This makes me suspect that it is not the resulting drawing that is consuming memory but the variables I use in the loops. It feels as if garbage collection isn't working properly: as if variables that go out of scopes are not released for cleanup.

 

I there anything I can/should do about this? I already do a 'save as' action at the end of each inner loop. Should I bring all variables outside of the loops? Should I nullify them?

 

Any help greatly appreciated.

 

// Tom

 

for (var i = 0; i < kNumRows; i++) {
for (var j = 0; j < kNumCols; j++) {

// I use a lot of local variables here

}

// saveas action

}

 

 

TOPICS
Scripting

Views

111

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

Community Expert , Dec 23, 2023 Dec 23, 2023

awesome, that's what's usually adviced, taking variable declarations outside of loops does help. 

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

that's a known problem in Illustrator, garbage collection doesn't work. The longer you work with it manually or automatically the slower is gets.

 

you have to restart illustrator to release memory.

 

can you post some of your code inside the loops?

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
Explorer ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

Hi Carlos,

 

Many thanks for your reaction. I think I may have solved my problem. Well, not really solved it but it's a work around for a memory leak: I simply declared all variables that are used within the loops outside of the loops. So new values get assigned on every iteration of the loop but the reserved memory locations stay the same (I presume). Not so elegant, counter to good programming practice, I believe, but it works.

 

Oh, and how I wish it was faster...

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 Expert ,
Dec 23, 2023 Dec 23, 2023

Copy link to clipboard

Copied

LATEST

awesome, that's what's usually adviced, taking variable declarations outside of loops does help. 

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