3 Replies Latest reply on Oct 17, 2013 11:43 AM by etatarevic24

    Memory Problems when running commands




      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:


      • The call to the C function seems to never cause any kind of hang up so I dont think that the C function is a problem
      • I do parse the data that comes from the C function and that doesn't seem to be a problem either
      • The problem seems to be within the function that traverses through the library and finds all the textfields
      • Another problem could be within saving some data to the document using "document.addDataToDocument", however I have reason to believe that is not an issue either which I will explain.


      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:


      PAGEFAULTCOUNT: 5535.2373046875


      WORKINGSETSIZE: 174132


      QUOTAPAGEDPOOLUSAGE: 906.0546875



      PAGEFILEUSAGE: -823828



      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.



      My stats:
      Windows 7 Pro Servic Pack 1 64 Bit

      Intel i7-3770

      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.



        • 1. Re: Memory Problems when running commands
          moccamaximum Level 5

          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.

          1 person found this helpful
          • 2. Re: Memory Problems when running commands
            etatarevic24 Level 1

            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:

            1. Get Data from a website using cURL
            2. Parse through this data and create a dictionary out of it
            3. Run through entire library checking every element for textfield and updating text in it, if needed
            4. Saving off what was in the textfield in a string
            5. Saving off string with original text using document.addDataToDocument


            When going in reverse:

            1. Get data from document.getDataFromDocument
            2. Parse through data and create dictionary out of it
            3. Run through entire library checking every element for textfield and updating text in it, if needed
            4. Save off empty string to document.addDataToDocument so to hopefully clear out what was in there before (not sure how to check if anything is saved still?)


            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.

            • 3. Re: Memory Problems when running commands
              etatarevic24 Level 1



              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