--- In flexcoders@yahoogroups.com, "cuttenv" <cutt...@...> wrote:
>
> 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
>
If you click Use Fixed Width Font on the right hand side you can see this much
better! :)