5005: Unknown error optimizing byte code

This is a really “interesting” error message that Flash throws in the Output panel and unfortunately there is no other explanation accompanying the message. At Jumpeye we’ve had to deal a few times with this error message which seems to be generated whenever working with large .fla files that make use of rather large amounts of code.

The solution would be to turn off the Optimizer and then recompile. You can turn the Optimizer off from the Publish Settings dialog box, select Settings for the “ActionScript 3.0″ option and in that dialog box disable the “Reduce file size and increase performance” option. You can do this whenever you are working on a very large project and get this error message. In the rest of the cases, you should leave this option checked.

Another solution I’ve found on the web (didn’t test it) is to delete the .aso files generated by Flash (Control -> Delete ASO Files) .

108 thoughts on “5005: Unknown error optimizing byte code

  1. Pingback: Notes & quotes » Blog Archive » 5005:Unknown error optimizing byte code…

  2. Got this working on a really large project… the crazy thing is, I can compile it twice in a row, back to back without restarting or quitting the IDE, and have it throw this error the first time, and work the next. Without altering any code at all.

    The only explanation I can come up with for that is the JRE running into some bad blocks of RAM. I’m not convinced that code changes which seem to work temporarily are actually doing anything. It’s logical that upping the JRE’s memory would give you a better chance of avoiding the problem, but I’m becoming convinced that this is indicative of a hardware issue on the machine doing the compiling.

  3. @Josh

    Hmmm… yours is an interesting approach and it could be true since in the case of large pieces of code, breaking it up into smaller ones does work. In this case I guess the problem would be either with the JRE’s memory management or maybe it’s an OS problem (though this happens in both Windows and Mac OS).

  4. We were experiencing the same memory erros when producing our games.
    We kept rising the JAVA_TOOL_OPTIONS ..during the development.. pretty high too .. as the project grew to a fla of 385mb.

    If we set it to high i would get “Error initializing JRE. You may need to reinstall Flash” when opening the fla..

    I’ve just did a testcase.. and it seems we have a very simple solution to the JRE Error..
    Just open your Flash .. and before opening the project.fla .. open a new empty fla .. publish it.. and close it again .. then open your project.fla .. and NO problems with the JRE or Publishing!!

    Seems it reserves the memory or something when you first start of publishing an empty fla :-D
    Normally i had to restart Flash after every publish of the big project(with lots of tweaking the memory).. now i can just keep on publishing the big project!

    This was tested on a Vista 32 with Flash CS3.

    Like to hear if it works for anyone :)

    With kind regards,

    Dennis Korf
    Isioux

  5. @Dennis Korf

    That’s quite an interesting solution you got there. Indeed, these memory problems are quite frustrating and I hope Adobe did manage to solve the issues (or some of them) with Flash CS4. Unfortunately I cannot confirm it for Flash CS4 since I didn’t have the chance to test it extensively (my main work is still done with Flash CS3).

    But I’m too interested to see if there’s anyone else conforming this solution for other platforms.

  6. We are also mainly working with Cs3 .. but we did buy a cs4 edition to test if it had the memory problems resolved.. as a “solution” to the cs3 memory problems..
    We didn’t test the cs4 update that came out last week.. but we did test the one that came out before that.. that’s the fix that adobe claimed to fix the bug.. but it actually didn’t ..you wouldn’t get the error anymore or something.. but you would get the WSOD.. so that wasn’t a solution.

    Didn’t try the “empty publish workaround” with the cs4 yet.. but i’ll do some tests today.

    It seems that Flash holds on to the memory need of the first publish.. and works with that for every other publish while it’s open.

    Best Regards,

    Dennis Korf
    isioux.nl
    Youdagames.com

  7. Tested the workaround on a:
    -vista 64 with cs3 : works aswell
    -Vista 64 with cs4(without the update fomr 2 weeks ago): doesn’t give an java or memory error.. so it doesn’t work there.. just a black screen

    Seems it only works for the JRE and “not enough memory” error..

    Dennis Korf
    Youdagames.com

  8. @Dennis Korf

    Thanks for the valuable info. Benjamin said in a previous comment that the problem was solved with the new update for CS4 (10.0.2) at least for Mac. Maybe that goes for Windows too.

  9. Nope.. collegue just tried the latest update of cs4.. no change in the publish effect.
    Actually.. since she did that update.. the cs3 is crashing alot :S .. not sure if it’s connected.. but it’s a big coincident.. :S

    Made a panel in jsfl ..

    var str = ‘fl.createDocument();’;
    str += ‘fl.getDocumentDOM().publish();’;
    str += ‘fl.getDocumentDOM().close();’;
    //str += ‘alert(“did publishclean”);’;
    MMExecute(str);

    If you make a panel from it.. and set the panel left of the properties panel..(so it has focus when you start flash) .. it publishes an empty swf when you start.

    Dennis
    Isioux

  10. Thanks Dennis :)

    I’m sure this will be of help to all of us. Especially since I’m not sure Adobe can/will do something about the problem (at least for CS4).

  11. OK

    read all of thispage and still no concrete answer for a normal PC using CS3
    my error message is actually 5003: Unknown error optimizing byte code

    - tried reducing file size to increase performance which hasnt really worked that great – allowed me to put on layer on.

    - THEN tried this JAVA_TOOL_OPTIONS variable thing which i prob didnt wrong. am i supposed to find a file and stick some code in there ?

    this is turning into a bit of joke now considering i only really have 25layers to the slideshow on my timeline. Would have used the xml way had the timing not be so god dam crap and be different on different machines which effectively f*cked up the loop

    so can ANYONE, please point me in some kind of direction as to any other solutions ?

    will reducing my pictures in files size make a difference ?

  12. Pingback: 5005エラー考 « Labs.Torques

  13. Thanks for this. Using Flash CS4 – increasing the Java VM heap memory limit worked a like a charm :)

  14. @ admin & all, thank you for adressing the topics you have in this post and the subsequent comment discussion, it seems Adobe has very little support for the JRE issue other than the CLASSPATH eVar one mentioned on their site.

    @ Dennis Korf, I am in your debt, your solution was the only thing that has resolved the issue for me, before I found this, I reinstalled flash CS3 3 times – as the error recommends, each time, the file would work fine for the first publish, but then it would appear again. Your work around explains why this phenomenon was occuring.

    I’m an solo indi Flash game developer, and I’m 5 months into a huge project (for me), when this seemingly unexplainable, unsolvable error cropped up. To be quite honest, it pushed me to near breaking point, Flash and AS3 are the only areas I am any way proficient in, due to it being affordable in both time delivery and resources I’ve sunk all my time into it, and now this was threatening to break my project and prevent me from finishing it, thinking it was my code or fla that was at fault, and not having any other avenues of development at my disposal I was at a BIG loose end, but now I know I can plough on, and the extra stress has gone! So Many thanks!

  15. Just want to express a heartfelt thanks to all posters here. I stumbled on the bytecode error two days ago. Did some reading and fixed it by turning off the optimizer. That worked fine for a day, then, as my fla increased in size (to only about a half meg), got the missing swf message. Did some reading here, and set up JAVA_TOOL_OPTIONS as -Xmx256M. My problem has gone away.
    As I understand it, because I am not using my timeline at all (everything is in .as files), flash is loading the whole works into the first frame. That suggests to me that my former limit was probably 512K in the first frame and is now 256 meg. Can anyone tell me if that’s the case and this problem will not come back unless I exceed 256 meg in the first frame? (I’m about halfway through this project and all subsequent classes will be the same size, so the eventual size should be in the neighborhood of 1.5 meg or so.

  16. Okay, so much for that theory. I just checked the size of another fla that WAS compiling with no problems, and it’s 2.8 meg (so far). So a 2.8 meg fla was working properly and a 500K one failed. ???

  17. @Paul

    Hmm…. I’m not sure why that happened. This is a nasty bug. I hope one day we won’t have to spend hours trying to find a solution.

    Though I’m curious if this happens only in Flash Professional or Flex has the same problem too ?

  18. @ Tezcat: Glad that it worked for you! :)

    The empty fla doesn’t work in every situation by the way.
    Although it does solve alot.

    I’m still having some problems now and then.. but that is that Flash makes my fla double the size after a save. Then it’s suddenly 360 instead of 180 mb. The strange thing is that it is small again if you do a “save as”.
    So if you’r suddenly having troubles with publishing.. compare your filesize with a backup version.. if it’s suddenly 2 times the size.. just do a “save as” and you can probably publish again.

    Hope the size bug is fixed soon aswell.. it’s been there for a while..and can reproduce it in CS3 and CS4(Latest builds)

    Dennis Korf

  19. Hi all,

    Assuming this is a dead topic now – posting in july ’09. Just wanted to post a thank you to tyler and others for the Java Memory fix. Setting to -Xmx32M worked fine for me – using cs4.

    I tried the empty.fla compile just previous to setting this environment var and it didn’t work, then tried it again after setting the var and it worked. Dunno if that is just coincidence.

    Had previously tried values from 128 to 1024M but no joy, so was delighted when the smaller value worked.

    Also, previous to this I had removed a CLASSPATH variable as suggested on Adobe’s site.

    Silverden

  20. @Silverden

    It seems this topic is not dead at all. People keep running into this problem a lot.

    Anyway, I’m happy you found a solution among the comments.

  21. Pingback: CouldHll’s Blog » Blog Archive » 奇怪的Flash bug

  22. More and more of this nonsense… a CS4 fla simply refused to publish giving the JRE error – even after I’d tried extending the JRE runtime memory to 256, 512, 1024… Switching it back to 64 (had been running at 128) did the trick. This is a little mad me reckons..!

  23. Wayne,

    I just had the same thing happen to me. I’d previously had to increase the JRE runtime memory to 256 to get rid of the error, but recently it started happening again and the only thing that fixed it was switching it back to 64. Bizarre. Thanks for your comment, I would have never thought to try that solution otherwise, and thanks to everyone else who has shared tips here too. Now it’s just a matter of staying out of the path of black cats and making sure I avoid walking under ladders and opening umbrellas indoors until I get this project over the line.

    Also, I believe -Xmx368M is a valid value as well. Perhaps that will work for someone.

  24. We had the same issue on windows Wayne.
    Especially with an xp pc using cs3.
    We’d turn it up till it gave some problems.. then we set it even higher.. this will work for a few times.. untill you hit the roof.. then you suddenly have to set lower values.

    At ChrisH: I believe every value you fill in will work. I’ve had times that it didn’t work with 255 .. but did work with 310. … or didn’t with 220 .. and did with 230. Don’t think it should be a “clean” memory number.

    With kind regards,

    Dennis
    Isioux

  25. Thank you all for all your input. I’m on OSX with CS4. By following 16, Josfk and 26, I was able to solve my 5005 error. Fantastic post! A lifesaver.

  26. Pingback: China News » Blog Archive » flash反编译杂记

  27. The 5005 problem seems to have been finally solved by upgrading CS4 to 10.0.2 on mac as Benjamin said in an earlier post. This is one nasty bug that has made my life miserable over the last couple of weeks.

  28. Okay, after hours of desperation I solved the problem.

    My Computer Specifications:
    Windows XP, 86x Architect
    Using both CS4 and CS3 (don’t ask why)

    Steps:
    1) Open the environment variables from the advanced tab in System Properties.
    2) Click new under the System Variables and type in:
    Variable name: “JAVA_TOOL_OPTIONS” and Variable value: “-Xmx128M”
    3) If you have Flash open, save your work if you have to, then close it.
    4) As soon as you re-open your fla Flash document just open: File -> Save and compact
    5) Now test movie, it should work!

    * Note: If this doesn’t work just change Step 2′s “…128M…” to each one: 256M, 512M, 1024M.
    Good luck!

  29. Pingback: 5005: Unknown error optimizing byte code « Mumbo Jumbo

  30. Thanks, thanks thanks! This post was a real time saver…Just to add to the anecdotes :
    I’m using CS4 on windows 7 with 8 gigs of ram . Despite all of my computer’s RAM, I had to go with -Xmx256M (higher values gave me the ‘reinstall flash’ message).

  31. Thanks much for help with this stupid error message. I apparently just hit it, would have thought the first 40k lines of actionscript would have been too much.

  32. @Dennis Korf : True. This error is showing its nasty face once again now I’m trying to split my project in parts. (I know…)

    - Clear ASO : no effect.
    - JAVA_TOOL_OPTIONS trick : not working for me.
    - Upgrading : worked in some case.

    Flash debugger is too limited in such cases.

  33. You could try and set your virtual memory extremly high aswell.

    I know it makes no sense.. as i have 8 gig normal memory.. but still, if you increase your virtual aswell you can raise the amount you fill into JAVA_TOOL_OPTIONS. On some computer we can raise it to 520!
    C: 12926 – 16989
    D: 10000 – 50000

    Further more.. make sure you set the visuals/skinning of your windows to as low quality as possible.
    Configuration screen / System / Advanced tab / “visual effects”

    With kind regards,

    Dennis Korf
    I Sioux
    YoudaGames.com

  34. Ow, and don’t forget to do a clean/empty swf publish before you open anything else!
    Otherwise Flash will calculate it’s needed memory for publish wrong.. by adding any used memory in that session.

  35. I have read this entire thread and thank-you for all the information everyone!

    I am running Flash CS4 V10.0 on Windows XP/4GB using AS3. I have seen all the errors mentioned.

    I have a huge Flash game (27GB swf) and I started with the errors:
    5005: Unknown error optimizing byte code.
    ReferenceError: Error #1065: Variable ComponentShim is not defined.

    Setting JAVA_TOOL_OPTIONS to 256M and bigger would give me the reinstall Java error. If I open AND run a small fla (775kb compiling to a 42kb swf), then my big one will work. Need to do this every time upon entering Flash Pro. This is annoying since I need to restart frequently working with a big fla. After working a while, compiling and running stops working or my background turns red or Flash Pro crashes. I miss Eclipse with the ability to just set your memory sizes and have it work.

    I tried 64M, did not get the reinstall error but did get the original 5005 error – not enough memory.

    Then I tried 128M and IT WORKED!!!! I can develop my game without opening the small one first. I did do the suggested Save and Compact, which might have helped, don’t know.

  36. Pingback: flasism» Blog Archive » Error 5005: Unknown error optimizing byte code

  37. Pingback: flash反编译杂记 | 星雨夜.冰雪花园

  38. Hi guys – delete the previously published .swf – also delete the ASO files.
    This generally sorts it out.

    Also try and watch out for Embedd tags – especially fonts.

  39. Aint life great, just bought Flash CS5 & upgraded it to the latest version and this 5003 problem is back….

    previously used the -Xmx256M for CS4, and worked great, now the same project wont compile anymore.. i really dont see why i paid £650 to Adobe for this crap

  40. Ok i found a solution for all of you who are having this issue again with CS5 here:
    http://www.bhootnath.in/blog/?p=73

    1. Quit Flash
    2. In a text editor, open the jvm.ini file from the following location:

    2.1. Windows XP: System Hard Disk\Documents and Settings\\Local Settings\Application Data\Adobe\Flash CS5\\Configuration\ActionScript 3.0\jvm.ini
    2.2. Windows Vista or Windows7: System Hard Disk\Users\\AppData\Local\Adobe\Flash CS5\\Configuration\ActionScript 3.0\jvm.ini

    (You might need to turn on “show hidden files”winking
    3. Change -Xmx128m to -Xmx256m and save the file.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">