Solved

dispose method in flex

Posted on 2008-10-12
7
2,138 Views
Last Modified: 2012-08-13
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
Comment
Question by:PsychoDazey
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:Savong
ID: 22704275
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
 
LVL 6

Author Comment

by:PsychoDazey
ID: 22704379
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
 
LVL 10

Expert Comment

by:Savong
ID: 22704452
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 6

Author Comment

by:PsychoDazey
ID: 22704464
Thanks, i'll check into that.
0
 
LVL 6

Author Comment

by:PsychoDazey
ID: 22751073
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
 
LVL 10

Accepted Solution

by:
Savong earned 500 total points
ID: 22759706
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
 
LVL 6

Author Closing Comment

by:PsychoDazey
ID: 31505488
Thanks again!
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FLex Calendar 3 548
flex4 : css styles 1 487
Flex 4.x in-line checkbox item editor/renderer using advanced datagrid control 4 1,727
Adobe upload listbox 2 498
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question