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:flexcod...@yahoogroups.com] On Behalf 
Of cuttenv
Sent: Thursday, December 03, 2009 6:04 PM
To: flexcoders@yahoogroups.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