Flash Slideshow Optimization Issues
OK if you can bear with me this is going to be complicated (or not I'm not sure). I have been tasked to make a flash slide-show it will go 开发者_Python百科on a mini net book like PC hooked up to a 32" monitor. The way it is set up is that I have a flash file set to go full screen and a folder with 11 images in them and a XML file. The flash file pulls the images and if needed text from the XML file. Some images are flat (no text) and some are set up for dynamic text, basically the thing is a digital signage app.
The application works fine, the problem is I am not sure how to optimize it for long term use. The images loading into it are 1920x1080 and about 500k-1.2mb but each cycle raises the amount of system memory to the extent that it crashes due to no available memory.
I am trying to figure out how to basically dump at the end of the cycle so that the memory use doesn't double each rotation. I know that if I remove event listeners that can have a big impact on it but I am not sure how or rather where in the application to do so.
Like I said everything is very lean in the flash file there is 1 frame with AS in it that is it nothing in the library or anything it is all dynamically generated, and I am sure that is my issue just don't know how to fix it.
Code:
Link to the Code, via Pastie
There is a external tween class I am using (I hated it, but couldn't figure out how to do the fades with out it) if it is needed so you can run and see what is going on i will zip it and share it too just let me know.
(sorry it was kind of a nightmare trying to paste it in here, the 4 space thing is cool but should have an option to wrap large blocks too.)
Really appreciate the help here, I really do thanks ahead of time.
From what you write I understood that with each new cycle you are loading the graphics again without dumping them before.
I'd either:
- Don't load the graphics again, so just reuse those which you already loaded;
- Whenever image disappears from the screen remove all references to it, and unset all listeners (even better use useWeakReference parameter) and forget about it. Garbage Collection should happen automagically.
It looks like you're loading in every image from the file system every time you need to display it - so there are a couple of problems with this approach.
1) You're creating new Loader objects every time the timer switches, which means you're going to end up with LOTS of loaders as this thing runs - and each loader is going to be holding an instance of the image it loaded. In your fadeSlideIn method you're not removing the Event.COMPLETE listener from the loader, so each loader will stay in memory forever.
2) Bitmaps in particular have some idiosyncrasies - I'm a little sketchy on the details, it's been a while since I've dealt with this, but I believe that when you clean up a bitmap you should always do myBitmap.bitmapData.dispose(), since bitmapData doesn't get GC'd nicely.
What I would do instead is probably to front-load all of your images into an array, and then loop through the array. You shouldn't have to use a loader more than once for any given image. You might try using something like LoaderMax (https://www.greensock.com/loadermax/) to streamline the loading process.
Good luck and let me know if you have any further questions!
精彩评论