Is assetLibrary.unload() working properly for SWFs?


Problems encountered when using the Swf library: Is this line of code working properly? I found that its implementation is empty, and after calling this, the memory is not reduced. If I use Assets.unloadLibrary, it will cause me to not load next time. What am I missing?

I believe we should be preloaded resources when an asset library is loaded, unloading should remove it from openfl.utils.Assets and discard some of this preloaded data, but ultimately whether things are removed from memory will be based on the garbage collector. Also if any of the loaded resources are still in use, it may still remain in memory. unload() is not an aggressive dispose() type of behavior. Any assets still in use in your project will still continue to work

	<library path="Swfs/LittleGirlSellingFlowers.swf"/>

How does this tag work in the code?How does this tag work in the code? Is it the same as the following example:

var library:AssetLibrary = AssetLibrary.fromFile("lib/test.json");

I want to be able to simulate a repository like the XML tag, so I can try to uninstall the resource through Assets.unloadLibrary.

Yes, it should be similar, though I believe that <library path="" /> may register it with the core preloader

So maybe add an stage.application.preloader.addLibrary reference after it is loaded

Memory still can’t be released, even reaching 500MB, it has no effect, I used the following API:


Hmm, then perhaps this might require some more testing

:grinning: Thank you, after today’s test, I found that the program contains memory leaks, and has successfully rescued the SWF release memory. Already able to release resources normally, great!

Share my experience:

All my swf are not using preloading.

Loading use case:

                    var library:AssetLibrary = lib;
                    _isLoaded = true;

The following example can successfully release SWF:


I believe you should be able to use Assets.unloadLibrary (levelTag) only to do it, but if not, let’s get some improvements into the core library

Thank you! This description is very good.