• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2165
  • Last Modified:

dispose method in flex

I have a flex app that uses a webservice to communicate with a sql server database.  I make calls to the webservice through flex, the webservice callse the database and returns the data in XML format and Flex parses the data as necessary(i.e. - to display in datagrids or comboboxes, etc.).  The app seems very slow...I am wondering if it is because it is still holding the xml data in memory...does Flex have a dispose or finalize method similar to .Net?  I have included an example of my code.
public function GetAssigneeTypes():void
	{
		var ws:WebService = Program.m_webServiceManager.getWebservice();
		ws.GetAssigneeTypes.addEventListener(ResultEvent.RESULT,LoadAssigneeTypes);
		ws.GetAssigneeTypes();
	}
	public function LoadAssigneeTypes(e:ResultEvent):void
	{
		Assigneetypes = new ArrayCollection;
		var dataSet:DataSet = new DataSet(String(e.result));
        if(dataSet.HasErrors())
        {
        	Alert.show(dataSet.GetErrorAt(0));
        }
        else
        {
        	var dataTable:DataTable = dataSet.GetTableAt(0);
        	{
	       		var keyPair:KeyPair = new KeyPair();
	       		keyPair.Name = "";
	        	keyPair.Value = "Assignee type"; 
	        	
	        	this.Assigneetypes.addItem(keyPair);
        		for(var index:int=0;index<dataTable.RowCount();index++)
        		{
        			var row:DataRow = dataTable.GetRowAt(index);
        			keyPair = new KeyPair();
	        		keyPair.Name = String(row.GetValue(0));
	        		keyPair.Value = String(row.GetValue(1)); 
	        		this.Assigneetypes.addItem(keyPair);
	       		}
        	}
        }
	var ws:WebService = Program.m_webServiceManager.getWebservice();
	ws.GetInitiators.addEventListener(ResultEvent.RESULT,LoadInitiatorTypes);
	ws.GetInitiators();
	}

Open in new window

0
PsychoDazey
Asked:
PsychoDazey
  • 4
  • 3
1 Solution
 
SavongCommented:
Unless your XML is absolutely huge I doubt the slowdown comes from keeping the XML.  If the XML doesn't have current references to it it ought to be garbage collected (similar to Java).  Have you run the profiler on your code, or tried tracing out Timer values to see where the slowdown is really happening?
0
 
PsychoDazeyAuthor Commented:
No, I haven't, I'm not sure how to run the profiler.  I am also re-writing some code because it is making 6 calls to the database to get 6 lists.  I am going to change it so it makes one call to get 6 different data sets then parses them...what do you think of that?
0
 
SavongCommented:
That should certainly speed up the process as calls for external data often slow down the whole process (particularly if they are called serially).  Here are a couple of links for more info on the profiler built into Flex Builder 3 if you have it available:

http://www.onflex.org/ted/2008/09/360flex-sj-2008-using-flex-builder-3.php
http://livedocs.adobe.com/flex/3/html/help.html?content=profiler_3.html
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
PsychoDazeyAuthor Commented:
Thanks, i'll check into that.
0
 
PsychoDazeyAuthor Commented:
hi savong -
making one call instead of 5 or 6 calls in serial made a huge difference in speed.   Unfortunately, I dont have flex3 so i cant run the profiler to see if I am holding alot of data in memory.  Instead of dispose, should I be clearing out all of my arrays when I navigate away from the page they are used on? If so, how and when do i call the removeall method?
If you feel this is out of the scope of this question just let me know and I will open a new one!

Thanks!
0
 
SavongCommented:
Basically any variables you want to be garbage collected should be set to null so that there is no longer any reference to the object.  Grant Skinner has a number of good articles on references and garbage collection for flash:
http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html
http://www.gskinner.com/blog/archives/2006/07/as3_weakly_refe.html
http://www.gskinner.com/blog/archives/2006/06/understanding_t.html
0
 
PsychoDazeyAuthor Commented:
Thanks again!
0

Featured Post

What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now