Class instances get GC'd when their applicationDomain gets GC'd, which is theoretically when there are no more references to that class instance or instances of that class and unload() has been called on the Loader of that SWF. I have not seen any unexpected behavior in that area.
If a SWF is loaded into the loading SWFs applicationDomain (like RSLs), there is no way to unload those classes. If a SWF is loaded into a child applicationDomain of the loading SWF, then that child applicationDomain can be GC'd. Modules call unload() right away so they get punted as soon as you are done referencing the module, otherwise we'd need some API where you'd have to remember to call unload(). SWFLoader SWFs don't unload until you load some other SWF with it or set its source to null. If you've loaded a module SWF and haven't created an instance of the module class and have no other references to a moduleInfo, that module is likely to be collected pretty quickly. Is that what you're seeing? Otherwise, someone should have to call unload() first. From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Josh McDonald Sent: Friday, September 12, 2008 5:59 PM To: [email protected] Subject: Re: [flexcoders] Re: SWFLoader unloading, whats the trick? Alex, Do you know if Class instances get GC'd? (as in instances of Class, not general objs) I've noticed Player likes to collect SWFs awfully quickly (even when there's *no* allocation), but I haven't done any experiments to verify the classes get collected as well (or not) yet though, but it might be weird if you're expecting a class to be around in order to getDefinitionForName() it later :) -Josh On Sat, Sep 13, 2008 at 7:19 AM, Alex Harui <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>> wrote: The Flex Profiler will tell you if you have other stuff that isn't being cleaned up. I posted on my blog some ways to use it. FP10 fixes many issues with SWFs not unloading. A test using the release build on a non-debugger player is the best way to see if you are getting false-positives. From: [email protected]<mailto:[email protected]> [mailto:[email protected]<mailto:[email protected]>] On Behalf Of djepyon Sent: Friday, September 12, 2008 12:11 PM To: [email protected]<mailto:[email protected]> Subject: [flexcoders] Re: SWFLoader unloading, whats the trick? Ok, I went ahead and added some manual clean up to the swf's I was loading using Event.UNLOAD. I'm basically setting values to null so they become candidates for garbage collection. Regardless, each time I load a file into SWFLoader the mem usage still jumps until the app becomes sluggish and ultimately unresponsive. I noticed the following bug (http://bugs.adobe.com/jira/browse/SDK-13097) and I'm assuming that is the issue I'm having. As I workaround I'm loading a single swf into SWFLoader and then having the loaded swf handle the loading of other external swf files itself. The class for something like this is as such: package { import flash.display.MovieClip; import flash.display.Loader; import flash.net.URLRequest; import flash.events.Event; import flash.events.ProgressEvent; public class LoaderSWF extends MovieClip{ private var loader:Loader; public function LoaderSWF() : void { loader = new Loader(); addChild(loader); } public function loadSWF(path){ trace("loadSWF(", path, " )"); var r:URLRequest = new URLRequest(); r.url = path; loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler); loader.load(r); } private function progressHandler(event:ProgressEvent) : void { trace("bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal); } } } --- In [email protected]<mailto:flexcoders%40yahoogroups.com>, Alex Harui <[EMAIL PROTECTED]> wrote: > > Each SWF really should stop its own audio and clean up. Trying to clean up on a SWFs behalf is likely a maintenance issue. > > From: [email protected]<mailto:flexcoders%40yahoogroups.com> > [mailto:[email protected]<mailto:flexcoders%40yahoogroups.com>] On Behalf Of djepyon > Sent: Wednesday, September 10, 2008 8:01 AM > To: [email protected]<mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] Re: SWFLoader unloading, whats the trick? > > > Alex thanks for the additional info. > > swfloader.content.stop() prior to setting a new source in this case > managed to stop the next swf at the beginning once it loaded. Not sure > why this happened. > > I did a bit of testing here and as far as I can tell when a > MovieClip's loaderInfo dispatches an Event.UNLOAD the MovieClip itself > has already been de-referenced. > > The timeline audio continues to play however. I've managed to fix this > problem (although this seems a bit of a hack) by calling > SoundMixer.stopAll() in the unload handler. I somehow doubt that this > actually deletes the Sound objects that were created so my guess is > that this could cause a big leak if many SWF's with timeline audio > were being loaded over and over. Perhaps the same problem would > persist even with SWF' with manually instantiated audio? > > Here's my quick fix. > > MovieClip(event.target.content).loaderInfo.addEventListener(Event.UNLOAD, > unloadHandler); > > private function unloadHandler(event:Event) : void { > > SoundMixer.stopAll(); > > } > > --- In [email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>>, Alex Harui <aharui@> wrote: > > > > I haven't used this event to shut down a movie, so I don't have > examples, but I think the recommended pattern is that the loaded SWF > is supposed to listen for the UNLOAD event on its loaderInfo. If the > main app is listening, then you're probably right that it is too late. > Of course, if you're about to set the SWFLoader's source you can > certainly call swfloader.content.stop() beforehand, but I think stop() > doesn't stop Audio/Video, just the frame timeline. You'll have to > have access to the loaded SWFs Sound instances which is why it is > "better" if the loaded SWF cleans up after itself. > > > > From: [email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>> [mailto:[email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>>] > On Behalf Of djepyon > > Sent: Tuesday, September 09, 2008 8:35 PM > > To: > > [email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>> > > Subject: [flexcoders] Re: SWFLoader unloading, whats the trick? > > > > > > Thanks guys. The feedback I get on here is always great. > > > > I was able to listen for UNLOAD on the SWFLoader. I tried a > > MovieClip(event.target.content).stop() but it seems that its already > > disappeared at this point and throws a null object reference error. > > > > Listening on the content object didn't trigger the event handler. > > Would it be better to use REMOVED or REMOVED_FROM_STAGE for this? > > > > Maybe I could get some sample code? > > > > --- In > [email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>>, Alex > Harui <aharui@> wrote: > > > > > > The SWFLoader unloads the SWF which just de-references the SWF bytes > > but does not clear references to objects created by code in that SWF > > which might be referenced by the player or other code, including > > Timers, Video, Audio, player events, etc. > > > > > > In FP10, there is a new unloadAndStop method that will supposedly > > clear this stuff out, but short of that, the child SWF should listen > > for an UNLOAD event and stop Audio and do other cleanup. > > > > > > From: > [email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>> > [mailto:[email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>>] > > On Behalf Of Josh McDonald > > > Sent: Tuesday, September 09, 2008 4:48 PM > > > To: [email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>><mailto:flexcoders%40yahoogroups.com<mailto:flexcoders%2540yahoogroups.com>> > > > Subject: Re: [flexcoders] SWFLoader unloading, whats the trick? > > > > > > IIRC, any loaded SWF that's no longer referenced will be garbage > > collected (and fairly quickly from my experience), but streaming audio > > (or video) is still referenced by the player so it doesn't go anywhere. > > > > > > -Josh > > > On Wed, Sep 10, 2008 at 9:40 AM, djepyon <ian@<mailto:ian@<mailto:ian@>>> > > wrote: > > > Does SWFLoader unload itself when you set a new source path? Then why > > > does timeline audio thats set to "stream" in the swf still continue to > > > play? Can give me the skinny on properly unloading a SWFLoader? Thx. > > > > > > > > > ------------------------------------ > > > > > > -- > > > Flexcoders Mailing List > > > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > Search Archives: > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups > > Links > > > > > > > > > > > > > > > > > > -- > > > "Therefore, send not to know For whom the bell tolls. It tolls for > > thee." > > > > > > http://flex.joshmcdonald.info/ > > > > > > :: Josh 'G-Funk' McDonald > > > :: 0437 221 380 :: josh@<mailto:josh@<mailto:josh@>> > > > > > > -- "Therefore, send not to know For whom the bell tolls. It tolls for thee." http://flex.joshmcdonald.info/ :: Josh 'G-Funk' McDonald :: 0437 221 380 :: [EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>

