Solved

dispose method in flex

Posted on 2008-10-12
7
2,141 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

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…
Configuring Remote Assistance for use with SCCM
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Suggested Courses

734 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