SWF not unloading


I have an issue with the SWF libray.
My app relies heavily on it, and I already did some fixes on some playback issues.

But this issue, I cannot figure…
It is an issue concerning the native targets.

My app loads swfs and plays them.
Once I am done playing an swf, I just remove every link to them and call the garbage collector.
Some memory is freed, but not everything that should be ( ie it doesn’t get back to 0 ) and after a while, my app crashes on Android ( on Windows of course I have enough memory ).

Does anybody has some hints, please ?

I’ve never used the SWF library personally, but if it’s not freeing up the memory entirely, then it seems to me that something is maintaining a reference to it that allows the GC to free up only some of the memory associated with it. One might try keeping all references to the objects in question encapsulated in a single class instance, which can then be “un-referenced” when you’re done with it. Maybe some examples of your code would be helpful, if you can?

Have you tried also using Assets.unloadLibrary if you are completely done with the SWF?

Thanks for your answer, but I am positive I unload everything, I triple checked, and I had it in mind when I wrote the code.
My question is mostly for people who know the SWF library, if any of them managed to fix this issue.
I’ll keep digging, thow.

I don’t use Assets.loadLibrary, because I don’t embed those SWFs.
I intend to have those SWFsavailable on a server so that users can download/remove them at will.

I use the SWF library, wich I forked to fix some playback issues ( https://github.com/openfl/swf/issues/34 ).
So I guess if I use the Assets.load, I will be stuck with this playback bug anyway.

So do you have any clue on what might keep memory in the SWF library?

You might consider testing the SWFLite target for how it handles memory.

It should load some light metadata, then load separate images using Assets.getBitmapData, with some modifications, I think it would be simple to dump just cached elements specific to the SWF, but otherwise, it certainly would be possible to simply dump the entire Asset cache for images.

The standard SWF handling is sort of arcane – the entire SWF is loaded and parsed, it’s somewhat difficult to track exactly where a reference could still be held. This should be resolved, but SWFLite is so much simpler at runtime, it’s way easier to wrap my head around. It doesn’t have animation added yet, but it could

I got this issue too.
If I made something like this…

var lib:SWF = new SWF(Assets.getBytes(path));
lib = null;

…then the memory will be free.
But if I create the MovieClips, like this:

var lib:SWF = new SWF(Assets.getBytes(path));
var clip:Sprite = cast (lib.createMovieClip(name), Sprite);
lib = null;
clip = null;

The memory will not be free.
So looks like createMovieClip() method is creating some var links, that doesn’t destroyed.
Still looking a way to clear the memory after using movieclips.
PS. Sorry for my English.

Your English is just fine. ;D

This might indeed be the same issue, because I do cast my MovieClips.
Maybe it affects the normal behavior.

Check the quick fix I have written earlier.
That might be troublesome if you have more that one SWF library, but otherwise, once you have deleted the library, and before you call for the garbage collection, call the static function:

If you have more than one SWF library, it won’t crash or anything, but all your MovieClips ( created from a loaded SWF library ) will stop playing.

Thank you for your answer, but I am at the end of my project and I won’t rework everything.
So I kept digging, and through some GC.trace and a tone of caffeine, I figure that the issue comes from the “format.swf.instance.MovieClip” class, that uses a reference to Lib.current.stage to tick on playing.
Since I use one library at a time, it’s not much of an issue for me, I just use the stopAllClips static function from this same class that remove the listening to the stage ENTER_FRAME event and allow for garbage collection, but for other projects it might not work.

I will open a issue tomorrow on the repository with as much details as possible.
But I have to ask, not to bother you, but to know if I should use this library on future projects: how serious are you about this library?
That’s my second serious issue, the kind that could have completely blocked me… and I don’t see much activity on the lib ( including on the previous huge bug I reported, that makes the lib fairly useless… ).

So really, I know you have a lot on your shoulders, I’m not complaining, I’m just asking for the sake of knowing: what’s the future of the SWF library?

Thank you, Horsetopus! Looks like your fix with…


…is working fine :smile:

Hi again :smile:

I apologize for the delay.

I believe that the SWF library is going to only become increasingly important, I believe that the future of the library ultimately is in the “SWFLite” format (or in something similar) because it is much easier to maintain and understand, works on all targets, and ultimately gets performance on most targets.

I have not personally done any work on multi-frame MovieClip support, my primary focus has been on making sure the tool integration goes smoothly and on single-frame accuracy. I would love to see strong animation support, though I know it may require some clever code to pool resources and make sure it is efficient. To that end, I appreciate your work and am definitely interested in seeing what you came up with.

I’m trying to think of what can be done to make sure that libraries such as actuate and swf get proper attention along with the main openfl repository, though there have been improvements to SWF lately.