Stack overrun
hi
i’m working on script reads text file, creates objects tags finds using recursive function, pushes these objects array, , adds these layout. works 400 objects, above “stack overrun” error. indesign’s way of telling me has run out of memory?
here first part of code:
var myfile = file.opendialog("choose data file"); var listingstring = "listing"; var myarray = []; if((myfile != "") && (myfile != null)){ var sourcefile = new file(myfile); sourcefile.open(); var mystring = sourcefile.read(); sourcefile.close(); var endindex; var listingcontents; var foundtags; var listing; var tagstart; var tagend; var tagcontent; function checkstring(startindex){ endindex = mystring.indexof("</" + listingstring + ">", startindex); if(endindex != -1){ listingcontents = mystring.slice(startindex + 2 + listingstring.length, endindex); foundtags = listingcontents.match(/<[a-z ]+>/gi); listing = {}; for(i = 0; < foundtags.length; i++){ tagstart = listingcontents.indexof(foundtags[i]) + foundtags[i].length + 1; tagend = listingcontents.indexof("</" + foundtags[i].substring(1)) - 1; tagcontent = listingcontents.slice(tagstart, tagend); listing[foundtags[i].substr(1, foundtags[i].length - 2)] = tagcontent; } myarray.push(listing); checkstring(endindex + 3 + listingstring.length); } } checkstring(mystring.indexof("<" + listingstring + ">", 0)); ... }
any suggestions on how can fix or optimise code? i’m thinking of trying split string multiple chunks , deal 1 chunk @ time, seems clumsy workaround.
you may have guessed code source file i’m working xml, though because don’t have experience xml , seemed more work i’ve done here went approach. thought may more flexible. might working true xml make difference memory issue (if that’s is)?
i’m working in cs4 in windows, had same problem in cs5 on mac tried.
i’d appreciate help.
further question above, there way manually clear memory? say, instance, populate myarray until length 200, layout objects, , clear , continue string fill next 200 objects? i’ve tried using myarray = [] once i’ve laid out objects, still stack overrun error.
More discussions in InDesign Scripting
adobe
Comments
Post a Comment