# Completely removing swf file from memory

**URL:** <https://forum.kirupa.com/t/completely-removing-swf-file-from-memory/441391>\
**Category:** flash\
**Created:** [December 20, 2014, 4:40am UTC](https://forum.kirupa.com/t/completely-removing-swf-file-from-memory/441391 "2014-12-20T04:40:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![flashdaddy](https://avatars.discourse-cdn.com/v4/letter/f/e36b37/32.png) [@flashdaddy](https://forum.kirupa.com/u/flashdaddy)\
**Post date:** [December 20, 2014, 4:40am UTC](https://forum.kirupa.com/t/completely-removing-swf-file-from-memory/441391/1 "2014-12-20T04:40:13Z")

</div>

Hi All,

I’m running into an annoying issue. I have a swf file that loads another swf file (i don’t know what that swf file is going to be, it comes from whatever URL i provide and I just load it). I notice in my Activity Monitor my memory of my flash plugin in FF and Chrome increase significantly when the swf file is loaded, when I’m done with the .swf file I remove it, but the memory is somehow still allocated (it’s like it never gets removed from memory). I attempt to unload the loader that is responsible for loading the swf (shown below)

```
myLoader.unload();
myLoader.unloadAndStop(true);	
removeChild(myLoader);
myLoader = null;

```

But that doesn’t seem to do it for me. In some cases, I then have to load _another_ swf file at some point and the memory increases again (and again with each swf being loaded). The memory seems to never free up. It just keeps increasing until the FF or Chrome plugin finally crashes. Can it’s my understanding that this is the way to remove a swf file, is there something I’m missing? The references that I looked up were:

> [@Completely removing externally loaded swf's](http://forum.kirupa.com/t/completely-removing-externally-loaded-swfs/233255):
>
> Hi! I have a new problem in the development of my site… I have a main swf that loads external swf’s using this code: var swfLoader:Loader = new Loader(); swfLoader.load(new URLRequest(swfArr[numArr])); addChild(swfLoader); Nothing wrong here… Just Checking… The problem is that in my main swf I have an Event Listener for stage resize… And inside each external swf too… So, when after I’ve loaded a 2nd external swf it’s still listening for the 1st swf event listener!! It throws the error: “Ty…

> [@removeChild .. removes from memory?](http://forum.kirupa.com/t/removechild-removes-from-memory/295715):
>
> Hi, I am loading in a swf into my file, via the loader class. When I remove this child … does all the swf remain in the memory, or is it discarded? I want to remove it entirely … var myLoader:Loader = new Loader(); myLoader.load("thisMovie.swf"); addChild(myLoader); // bit and bobs later/////////////// removeChild(myLoader); Thanks … … . . . . . … . . .

> [@Help unload/remove previous swf file](http://forum.kirupa.com/t/help-unload-remove-previous-swf-file/306901):
>
> I’m confused about how to remove the previous load swf file.like i have this image.swf that loaded first then that image is a button so when i click that button it will load another swf file, my problem is that, the image.swf file still viewable when you load the 2ns swf file. how could i completely remove the image.swf file? i found some codes, but it was not completely working on removing the previous loaded swf file. thanks a lot [image]

Which sound like similar issues, but those threads were never responded to. Your help is so much appreciated!

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [December 20, 2014, 8:48am UTC](https://forum.kirupa.com/t/completely-removing-swf-file-from-memory/441391/2 "2014-12-20T08:48:36Z")

</div>

Hey flashdaddy,

The great danger of loading other SWFs is that you’ll lose control of them. Adobe never devised a perfect way of controlling the effects of loading another SWF, so you have to be judicious with what other SWFs you load.

I don’t think there’s a great way for you to solve this problem, given that you’re not willing to impose any restrictions upon the SWFs that you’re loading. Of course, it’d be helpful if you provided examples of the troublesome SWFs; it’s always easier to deal with concrete examples.

The important thing to understand with loading external SWFs is that you’re granting a lot of authority by doing so. This is similar to how it’s potentially dangerous to load an external JavaScript file onto your site. There are sandbox rules, but they’re not particularly strict. The _vetting_ is an important component of letting anyone use your own code as a conduit. Flash isn’t really built to subdue your own choices of what code to load.

* * *

On the other hand, if you can load the SWF bytes from a domain over which you have control, then you don’t have to care about any of the nonsense up to which those SWFs might get. You can use the powers of static analysis to sandbox any external dependencies, but only if you’re willing to host that data yourself. Flash Player will only give you control over data in your provenance.

---

<div class="post-metadata">

**Author:** ![flashdaddy](https://avatars.discourse-cdn.com/v4/letter/f/e36b37/32.png) [@flashdaddy](https://forum.kirupa.com/u/flashdaddy)\
**Post date:** [December 22, 2014, 6:15pm UTC](https://forum.kirupa.com/t/completely-removing-swf-file-from-memory/441391/3 "2014-12-22T18:15:37Z")

</div>

Thanks for the response. I’m more interested in just removing the swf _“the right way”_. Fortunately the swf files that I’m loading aren’t really problematic, I just think I’m not removing them correctly from my project using the methods shown above. I think there is a footprint being left in the memory because I see the file size increase and when I remove it it, I see it decrease a little, but not a lot. Then when it loads again, it increases again and so forth (for each load, it steadily stays on an upward trend of memory usage even though it goes down a little when it’s removed).
