Question :=(.
I'm making application for android. (Main frame made air and load swf files)
It's almost finished other than "memory optimization".
So, i'm wondering is this. ------->
I need to remove directly when swf file unloaded. and i know it's hard.
but, some swf files has 30 ~ 50 mb. (this is flash animation).
memory duplication made problem in android...
so, my question is how can i delete directly swf file memory.
please. let me know. i need to sleep :(
There is no such thing as 'delete directly swf file memory'. You need to remove all references to anything that you've used in that swf - that's the only way. The file itself doesn't stand as a whole in the memory. Instead - each object you've used from it goes into memory, and needs to be cleared by garbage collector once it's completely not used (not displayed, no references to it).
Related
All my SWF files run the same script class, There are a lot of .swf files to be updated after making some changes in that script class, Normally to see changes in SWF files I would open the FLA files and compile. Since there are thousands of SWF it will take too much effort.
is there any way to update all existing .swf files without a need to re-compile .fla files
Thanks for your consideration.
I guess by "refresh" what you actually mean is recompile.
To automate that, you have a two options:
1- JSFL, which is a pain in the ass.
2- Write a program that will compile every .fla throught command line, which somehow can be even more painful
I'm not an expert in both of the solutions so let me just give you a guide on how to do it the first way: http://gskinner.com/blog/archives/2004/08/jsfl_fla_batch.html
By definition, it's impossible to create or modify a (million of) swf (pdf, doc, gif, php...) file without opening it.
So I'm quite aware of flash/as3 garbage collecting causing memory leaks, and all the questions on the net.
Our software runs a swf, that loads in other swfs, videos, and images. It is expected to run a week without being restarted. generally, the player barely makes it a week without crashing from using too much memory. the swf will load in other assets based on the time of day, or if the schedule has changed. I wrote a simple resource manager so that it keeps track of what is used and what isn't, and will unload and set the unused assets to null. it does this unused check every hour, but it still seems that memory still doesn't go down after these assets are unloaded, and the memory leak continues to grow.
What I'm wondering, and can't seem to find, is can you expect flash to for SURE eventually release memory that is unused? or is there a possibility that flash may NEVER release unused memory?
It's really hard to find where memory-leaks come from without tools.
During game developpement I use Flash Builder Profiler, allow me to see if all my objects are destroyed when they are supposed to be.
In your case I would take a look at Adobe Scout :
http://gaming.adobe.com/technologies/scout/
Introduction to adobe scout: https://www.youtube.com/watch?v=yUHipsoGB2U
Using those tools during and after game developpement are the way to deal with memory-leaks.
Flash should be garbage collecting things that are no longer referenced. Is it possible that there are still references to whatever you're trying to garbage collect? You'll need to use removeEventListener() anytime that you've used addEventListener() to ensure that all of the references get deleted.
So, if you add an event listener to an object:
foo.addEventListener(Event, functionName)
Then you'll need to remove the reference when you're deleting the object:
foo.removeEventListener(Event, functionName)
It should be garbage collecting. Are you sure you're not inadvertently holding onto a reference to the unused objects? It's pretty easy to forget to remove an event listener, which will prevent an object from being collected when the GC runs.
Consider an AIR application which can load any number of third-party SWF files one at a time for display. Like a Web Browser.
The problem is that these SWF files may have EventListeners which have not been removed, etc.
Will Loader.unloadAndStop() be enough to garbage collect these SWFs?
If not- is there an approach which will (maybe a new NativeWindow for each SWF, then close the NativeWindow when done. Will that completely GC?)
Separate native window or loading inside a browser control can be a way for third party SWFs you have no control over. This adds a lot of overhead otherwise.
Unfortunately, you cannot ensure proper sandboxing of the loaded code (the display objects, most importantly, stage cannot be hidden from the loaded code). If the loaded code had added a listener to stage (which is a common thing to do if you need keyboard events), then it will not unload.
This is, however, impossible on mobile devices, where SWF format itself is different.
A while back I had a similar issue with externally developed components to which we didn't have the source, and it was sandwiched into our application. The best I could do / think of, was to do what the nuclear industry does - when things go bad, at least contain it in concrete so it doesn't spread more than it has to.
My solution was to build a 'component pool' so that as the contaminated objects were requested to be "clean" they were put in a separate holding area to be reused when needed - this way only the minimum number needed were ever created during a running session.
You should make a public static function to remove all the listeners in the loaded swf file(s) before you GC it.
I would like to be able to
create a folder for the copied video frames
access the individual frames frome a .flv video file and/or .swf file
save these frames to the auto-created folder
I assume one would need to do this using Action Script 3 to scan through the .swf and .flv files and extract the frames.
Are there gudies on how to do this?
You need to know WHAT frames do you want to extract. For example:
extract 20 frames in regular interval from the video clip
extract frames at 15 seconds interval
extract frames at keyframes (scene changes)
I guess that you don't have to use as3 to extract frames, but can also create the script in some other language. Central piece to frame extraction could be ffmpeg, as described in this article.
If it is as3 solution i would do following
- make a loader which loads your fla/flv
- add enter frame event listener to it and on each frame draw loader object to buffer, if you ever done any loading and drawing, this will probably take you 10-20 minutes to set up.
This is pretty much the only straigt-forward solution if you're dealing with code-based animations, videos can be handled in different and easier ways i guess.
You will face the challenge of saving the output tho. Flash player can save images on your computer, however only by prompting you to save the file. You will need to use functions available only in Air player if you want to save anything without prompts.
My website is entirely flash based, it moves around a 3D model which was given to me as chunks of video that I've converted to FLV files. I'm using the FLVPlayback component to control the video inside of my program. While running memory checks using System.totalMemory I've noticed that whenever a video is loaded, it will eat up a chunk of memory and even when I remove all the event listeners from it(they are all weakly referenced), remove the component from its parent, stop the video and null the component instance, it still will not give that memory back.
This has been bothering me since I started working on this project because of the huge amount of video a user can potentially instantiate and load. Currently every video is loaded into a new FLVPlayback instance whenever it is required, but I have read that perhaps the best way to go about this problem is to simply have a global FLVPlayback instance and just reload the new video into the old instance, that way there would only be one FLVPlayback component in the application's memory.
Has anyone else run into this problem as well? Have you found a better solution than using a global instance that you just re-use for every new video?
I've never really liked the components, they're a bit dodgy. This particular problem seems to be common, and the somewhat annoying solution is, as you're suggesting, to only have one FLVPlayback and reuse that.
Here's a blog post about it
You can't help the memory problems much until Flash adds destructors and explicit object deletion, unfortunately. See this thread:
Unloading a ByteArray in Actionscript 3
There's a limit to how much memory Flash applets can use; the GC seems to fire upon reaching that limit. I've seen my memory-easy applets use as much as ~200MB, just because they run for hours on end and the GC doesn't want to kick in.
Oh, and I don't think using a single instance is an elegant solution, either. Currently I just write a dispose() function for my custom classes, waiting for some day when it can be turned into a proper destructor.
From what I gather after a lot of testing is that flash dynamically loads in libraries and components as needed but never garbage collects that data. For instance, if I have a website or an Air app that uses the FLVPlayback component, the actual component and libraries associated with it aren't loaded until a new FLVPlayback() instance is created. It will then load in the library and component into memory but you will never get that space back until the program / website is closed. That specific instance with the video inside of it will get garbage collected and release some memory as long as you remove listeners from it, take it off the stage, and set it to null.
Also, if you are doing individual videos, the VideoPlayer is much lighter weight, and cleans up nicer.
Thanks for the responses, the links to the other blog questions were helpful as well, I had read all of Grant Skinner's info on garbage collection too, but searching through those links and going back and re-reading what he had originally said about GC helped refresh the old noggin. In addition to nulling and re-instantiating that single FLVPlayback component, I also realized that I wasn't correctly unloading and destroying my Loader instances either, so I got them cleaned up and now the program is running much more efficiently. I would say the memory usage has improved by around 90% for the site.
#aib I will admit the single instance solution isn't elegant, but because flash just won't let go of those FLV files, I'm kind of stuck with it.
#grapefrukt I detest the flash components, they typically cause more grief than time saved, however in this case I had a lot of cue points and navigation stuff going on with the video files and the FLVPlayback component was the best solution I found. Of course I'm still fairly new to the ActionScript world so perhaps I over-looked something.
Unfortuantely, thats just the way flash handles it. Not particularly smart, but it works for most people.