So at the end of the main function call everything would go out of scope and be 
eligible for garbage collection? The issue is that I see a LOT of functions 
definitions that are not being garbage collected and I am trying to pin point 
if using named functions like this could be the problem. I know you can create 
strong references on Event Listeners and that causes things not to get garbage 
collected. What are other ways that functions might not be garbage collected?

private var run:String = "one";
private function main():void{
    function boo()void{
       Alert.show("boo hoo");
    }
    foo(boo);
}
private function foo function(bar:Function):void{
    var str:String = "Hello";
    function fnc1():void{
       function fnc1a():void{
          Alert.show(str+" function 1 A!");
          bar();
       }
       function fnc1b():void{
          bar();
          Alert.show(str+" function 1 B!");
       }
       runFuncs(fnc1a, fnc1b);
    }
    function fnc2():void{
       Alert.show("WOW This can be confusing!");
    }
    if(run == "one"){
       fnc1();
    }
    else if(run == "two"){
       fnc2();
    }
    else{
       bar();
    }
}

private runFuncs(a:Function, b:Function):void{
    a();
    b();
}


--- In flexcoders@yahoogroups.com, Alex Harui <aha...@...> wrote:
>
> Once it goes out of scope it is eligible for GC unless there is another 
> reference to it
> 
> Alex Harui
> Flex SDK Developer
> Adobe Systems Inc.<http://www.adobe.com/>
> Blog: http://blogs.adobe.com/aharui
> 
> From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On 
> Behalf Of cuttenv
> Sent: Thursday, December 03, 2009 7:08 PM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Re: Inline functions and Anonymous
> 
> 
> 
> Ok what about the second example though? Those are all named functions, but 
> as you can see it gets messy rather quickly. In the example below would the 
> foo function ever get garbage collected because it has all those other 
> functions in it as well...
> 
> --- In flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>, 
> Gordon Smith <gosmith@> wrote:
> >
> > I've heard that anonymous functions are significantly slower because the 
> > runtime has to create an activation frame for them. We use very few 
> > anonymous functions in the Flex framework.
> >
> > Gordon Smith
> > Adobe Flex SDK Team
> >
> > From: flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com> 
> > [mailto:flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>] On 
> > Behalf Of cuttenv
> > Sent: Thursday, December 03, 2009 6:04 PM
> > To: flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>
> > Subject: [flexcoders] Inline functions and Anonymous
> >
> >
> >
> > Hi everyone, I have a quick question. Is there any performance gain when 
> > using an inline or anonymous function in flex??
> >
> > For example let's say you have:
> >
> > private foo function():void{
> > var btn:Button = new Button();
> > var str:String = "Hello Guys";
> > btn.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void{ 
> > Alert.show(str); } );
> > }
> >
> > So I realize the advantage to using inline functions is that you can use 
> > local variables that are defined in the scope for example the str variable. 
> > But what happens when you have the extreme case like this:
> >
> > private var run:String = "one";
> > private function main():void{
> > function boo()void{
> > Alert.show("boo hoo");
> > }
> > foo(boo);
> > }
> > private function foo function(bar:Function):void{
> > var str:String = "Hello";
> > function fnc1a():void{
> > function fnc1a():void{
> > Alert.show(str+" function 1 A!");
> > bar();
> > }
> > function fnc1b():void{
> > bar();
> > Alert.show(str+" function 1 B!");
> > }
> > runFuncs(fnc1a, fnc1b);
> > }
> > function fnc2():void{
> > Alert.show("WOW This can be confusing!");
> > }
> > if(run == "one"){
> > fnc1();
> > }
> > else if(run == "two"){
> > fnc2();
> > }
> > else{
> > bar();
> > }
> > }
> >
> > private runFuncs(a:Function, b:Function):void{
> > a();
> > b();
> > }
> >
> > nice eh? >_< So what are the disadvantages?? My main concern here is memory 
> > leaks and performance. I was looking at the profiler and I think the 
> > garbage collector may not be cleaning up all the unused functions.
> >
> > Please help :D
> >
>


Reply via email to