Solved

dispose method in flex

Posted on 2008-10-12
7
2,133 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now