Skip to main content
Participant
September 19, 2008
Question

Memory Error in Bridge while running a script with multiple moveTo()'s.

  • September 19, 2008
  • 3 replies
  • 484 views
I have written a script to create folders based on the names of assets in the parent folder, then move the assets with matching names into the appropriate folders. The script runs perfectly up to somewhere between 1,000 to 1,500 images moved and then I receive a memory error from Bridge.

I have been running this on folders with an excess of 25,000 assets in them. My work around was to put a simple counter in the script to let me know when 1,000 assets had been moved, throw up an alert, and then I would view the Task Manager to let me know when the CPU usage had dropped below 50% and would ok the alert, then it would run the next 1000 assets.

My question, is it possible in scripting to monitor your memory usage to allow a pause in the script so Bridge processing can catch up?
This topic has been closed for replies.

3 replies

September 19, 2008
Don't do that!

$.sleep() doesn't "sleep". ExtendScript is not multi-threaded. $.sleep just waits on the $.sleep() command to execute. It actually blocks all processing rather than free up the processor to do things like garbage collection.

First try the $.gc() command. To my knowledge there is no way to track ES' memory usage.

If that doesn't work, try scheduling a task...

Let's say that you find that after 1000 moves, it takes 60 seconds for the processor to cool off:

doAThousandMoves = function() {
// execute 1000 moves
}

app.scheduleTask( "doAThousandMoves()", 60000, true );

The way I would actually code this is to scan the folder tree and create a global array that contained all of the files to be moved.

I would then move them 1 at a time, shifting them off the array. Something like this:

var mover = {}; // global object declaration
mover.init = function() {
mover.files = new Array();
// fill mover files with the file objects to be moved.
app.scheduleTask( "mover.move()", 10 );
}
mover.move = function() {
var i = 0;
while ( i++ < 1000 ) {
file = mover.files.shift();
// move file
}
if ( mover.files.length > 0 ) {
app.scheduleTask( "mover.move()", 60000 );
}
}

In fact, you should probably break this into chunks of about 10 or so at a time (you can reduce the gap between calls). Doing so will make the operation appear to be running as a background process.

Regards

Bob
Participant
September 19, 2008
Thanks, I will give that a shot. I was going to try the $.sleep(mms), but I assume the sleep stops the thread which only delays my memory issue. I will post my results. Thanks again.
Known Participant
September 19, 2008
> My question, is it possible in scripting to monitor your memory usage to allow a pause in the script so Bridge processing can catch up?

If it's a garbage collection issue, you should be able to replace your alert()
call with a call to $.gc() which will force the garbage collector clean up memory.

You don't want to be actually monitoring JS memory consumption from the script.

-X
--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com