开发者

My Application running very slow

I develop a application based on Advance data grid. In this grid every column add with help of item render and I have added check box in all the column header also.In the Grid i used xml data provider. I am creating xml as string and cast this string in to xml. When i click any cell it takes 10-13 sec and in the cell click handler i get value of System.totalMemory is 255205376.

Please any one suggest me what i will do.

Thanks

My Xml crating Code

public function CreateDefaultXml(PojectionPeriod:int):XML{
            var xmlstring:String="<root>";

            xmlstring+="<row>" + 
                    "<Itemname>Item</Itemname>" + 
                    "<Unit>Unit</Unit>" + 
                    "<Cases>Cases</Cases>" + 
                    "<row>1</row>" ;

                for(var i:int=0;i<PojectionPeriod;i++){
                    xmlstring+="<projection_"+i.toString()+">";
                    xmlstring+="<projectionTxt/>";
                    xmlstring+="<growthValue/>";
                    xmlstring+="<projectionFormula/>";
                    xmlstring+="<constantgrowth/>";
                    xmlstring+="<growthWith/>";
                    xmlstring+="<timeProjection/>";
                    xmlstring+="<formula/>";
                    xmlstring+="<IsError/>";
                    xmlstring+="<Image>l</Image>";
                    xmlstring+="<DisplayprojectionTxt/>";
                    xmlstring+="<Style>" + 
                                    "<FontColor></FontColor>"+
                                    "<CellFill>0xffffff</CellFill>"+
                                "</Style>";
                    xmlstring+="<DecimalValue>0</DecimalValue>";
                    xmlstring+="</projection_"+i.toString()+">";
                }
                xmlstring+="<RowSelected>false</RowSelected>";
                xmlstring+="<ItemNameStyle>" + 
                        "<FontColor></FontColor>"+
                        "<CellFill></CellFill>" + 
                    "</ItemNameStyle>" +
                    "<UnitStyle>"  + 
                        "<FontColor></FontColor>"+
                        "<CellFill></CellFill>"  + 
                    "</UnitStyle>"
                    "<CasesStyle>" +
                        "<FontColor></FontColor>"+
                        "<CellFill></CellFill>" +
                    "</CasesStyle>" ;
                xmlstring+="</row>";

            var headerxmlString:String="";
            headerxmlString+="<header>" + 
                        "<Setting>" + 
                            "<Currency></Currency>" + 
                            "<Period></Period>" + 
                            "<NumberOfPeriod></NumberOfPeriod>" + 
                            "<StartPeriod></StartPeriod>" + 
                            "<PeriodFormat>" + 
                                "<Sequence></Sequence>" + 
                                "<Month></Month>" +
                        开发者_运维知识库        "<Year></Year>" +
                                "<Separators></Separators>" +
                                "<FontColor></FontColor>"+
                                "<CellFill>0xffffff</CellFill>"+
                            "</PeriodFormat>" + 
                            "<NumberFormat>" + 
                                "<Seperator></Seperator>" + 
                                "<Negative></Negative>" + 
                                "<HardCoded>" + 
                                    "<FontColor>0x000000</FontColor>"+
                                    "<CellFill>0xffffff</CellFill>"+ 
                                "</HardCoded>" + 
                                "<Calculated>" + 
                                    "<FontColor>0x000099</FontColor>"+
                                    "<CellFill>0xfffe83</CellFill>"+
                                "</Calculated>" + 
                                "<DecimalDigit>2</DecimalDigit>" + 
                            "</NumberFormat>" + 
                        "</Setting>"+
                        "<projectname/>";

            headerxmlString+="<headerColumn>";
            var headerArr:Array=new Array();
            for(var j:int=0;j<int(GlobalVariables.GlobalVariables.ProjectionPeriod)+3;j++){
                headerxmlString+="<column_"+i+">"
                    headerxmlString+=false
                headerxmlString+="</column_"+i+">"                  
            }
            headerxmlString+="</headerColumn>"
            headerxmlString+="</header>";
            GlobalVariables.GlobalVariables.HeaderXMLs=XML(headerxmlString);
            xmlstring+=headerxmlString;         
            xmlstring+="</root>";
            return XML(xmlstring);
        }


Hard to say exactly where you problem is without looking at your code; but the first step is to use the profiling tools in Flex builder to get a better idea about where the memory is being allocated and which methods are using up all that time.

How many 'elements' are there in your XML collection?


If you are setting the dataSource property to your CreateDefaultXML function, Flex is going to call that function every time the data is sorted, a cell is clicked or if your application window is resized. Pretty much any event that affects the AdvancedDataGrid or its contents will cause that function to be called again.

It may be better to call the CreateDefaultXML function in your components creationComplete event handler and output the value to a Bindable variable. Then have your AdvancedDataGrid use the Bindable variable as your dataSource so you're not recreating it over and over. (Assuming that you have your dataSource set to CreateDefualtXML() of course.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜