I have a script, written in JSFL, to find all textfields in a FLA's library and then changing the text. I do also extend flash to use a C class that I have written to cURL some data and then return it back to flash. The current issue is that in some files it takes a very long time and a lot of memory to complete the required command. It does not get "stuck" every time but it does seem to happen most of the time.
I do have a few conclusions that I have come up with:
Since this script changes the text it also needs to keep track of what text was in the file originally. I do that by saving some data, as a string, to the document. Then when I run the command again and convert the textfields back to what they were I load the data from the document using "document.getDataFromDocument". After that is completed I save over the saved data with an empty string ("") in order to possibly remove some of that saved off data from memory. I'm pretty sure the "get" is not slow nor is the "add".
Most of the time (> 50%) the first time I convert is quick. However, most of the time when converting back to what text I had it gets "stuck". By "stuck" I mean memory usage starts to go up, all the way up to almost 7 GB when normally it run at or under 1GB. The function ends up completing but taking 5+ minutes when really it should only take about 10 seconds.
Here is some of the memory usage I printed out last time memory went up:
I dont understand the negative numbers. Also in this case I went from < 1GB memory usage up to 6.3GB using Windows Task Manager to view memory usage.
Windows 7 Pro Servic Pack 1 64 Bit
8 GB Ram
NVIDIA geForce GTX 560
If I could debug this somehow or print out what it is currently doing that might help me figure it out but since Flash ends up "not responding" while the script is running I can't see anything happening. I guess maybe I could write to a file over and over which I could view as it is running and now that I think about it that would help and I'll try that next.
In the meantime, does anyone have any idea as to what could be causing it to get "stuck" and elevate so high in memory usage? I have tried to optimize everything in the script as much as possible, without going to extremes.
If any of this doesn't make sense or you need more info please let me know.
Here is a good list of some known bugs with JSFL:
My first guess, when i hear that you are reading/writing files would be that it is a rights/owner/permission and/or location of the files/folders you work on/from.
Avoid network drives, and use only directories with no special charcaters, avoid spaces (in file/foldernames) too.
Is there a resaon why you don`t use xml to change all the text in the texfields?
This construct of yours seems extremly complicated for the simple task it is supposed to do.
Thanks for the "gotchas" list maccamaximum. I'll review that to see if I am doing anything similar.
As for why I dont use xml is mainly because I want to save the original data somewhere within the file. The only way I know of doing this is to use the above mentioned "document.addDataToDocument" which takes in
"integer", "integerArray", "double", "doubleArray", "string", or "byteArray". I am not sure if XML would fall in under one of those and even if it did I dont really see a big difference in me parsing out a little bit of text or using xml which will act very similary to what I'm doing with a string.
It really doesn't seem so complex to me but if you can see a simpler way I would love to try it.
Just to review what im doing:
When going in reverse:
The parsing is relatively simple and doesn't do any weird saving or reading of files. The problem seems to be in going through every element in the library.
Thanks for the help though. I'll update in here once I run through a few more tests.
What i have noticed if I run the first command, which runs quickly and then close the document and then run the command to convert back to original everything works just like it should. I don't get huge memory usages and it run very quickly.
If I click on an item in the library, just once, so that it is selected and appears in the preview window, that is when I get "stuck". It doesn't seem to matter what command is run and how many times.
I might try deselecting any items and running again to see if that fixes it.
EDIT: Tried deselecting everything before traversing through all the elements and that didn't help at all.
Also is there any way to somehow clear whatever the script has done memory wise to the document?
Message was edited by: etatarevic24