Home

Main Menu

Code optimization and Actionscript 3 PDF Print E-mail
User Rating: / 2
PoorBest 
Written by pranjan   
Thursday, 13 November 2008 19:35

To comment for this article click this link. 

Everytime after finishing bulky code writing, you would often need to optimize your code to minimize memory consumption. This is little bit tedious job for who wouldn't keep their eye over code optimization and AS3 coding guidlines.

 First and foremost thing is CODE OPTIMIZATION IS NOT A BIG PROBLEM IF YOU TAKE CARE OF FEW THINGS.

Lets start what you should remember while writing code and how.

 Lets go with how first. For a developer coding is just like daily routine so you must have to follow desciplines/rules/protocols while coding.

Now following are few things that you should always keep in mind.

 If you start a very new project from scratch, always create an interface that would have just 2 things. One would be toString()  and other is dispose(). 

 /**

* Interface implemented by each class.
* @author Your Name
* @version 0.1
* @date 14-11-2008
*/

package com.core
{
public interface ICore  
{
function toString():String;
function dispose():void;
}
}

Always implement this interface into your every class whereever you write. This may help you to collect garbage.

In each and every class don't forget to update this dispose method. This would contain everything that you need to distroy.

/**
* Dispose.
* @author Pravin Ranjan
* @version 0.1
* @date 16-7-2008
*/

public function dispose():void
{
removeChild(_mcTooltip);
for (var i:String in _arrItems)
{
_arrItems[i].dispose();
removeChild(_arrItems[i]);
}
_arrItems = null;
_mcTooltip = null;
_objMain = null;
Main.getInstance().removeChild(this);
}

Often programmer think that they have removed the sprite and everything will washed away. AS3 JIT is right now not so intelligent to remove what you think. Therefore it is always keep in mind to remove things manually. I don't think this is a bad habit. You can write 5000 lines of code so better if you could write 5200 lines of robust and memory intelligent code.

What precisely I am talking about is to remove each and every instance you have created, whether it could be local, class variable or global (static). Remove everything manually.

As you know some data types allocate memory to copy similar things. Others use reference like array and objects.

Remove each and every events that you have created. In some cases, lets say, you use an event only one time, destry it immediately. In another case like call a class, assign listener and forget. In this case too, remove listener immediately.

var obj:SwfExportDlgBox = MessageBox.getInstance().showSwfExportDialog("Title", "Message");
if (obj != null) obj.addEventListener(MessageEvent.MSG_OK, clbSWFExport);
 

private function clbSWFExport(event:MessageEvent):void
{
event.stopImmediatePropagation(); //Generally you don't need propagation.
//Remove the listener.
event.target.removeEventListener(MessageEvent.MSG_OK, clbSWFExport); 

//START YOUR CODE HERE. 

}

Always set each object, string, class instances to null just after use. Keep in mind that a static variable never dispose itself untill you clean it manually. If you use a static variable in a class, always set it to null before removing it. If not so, JIT alwyas think about you class that it has some variable and should not be cleaned. :D and you may think opposite.

Always dispose a bitmapdata object. A bitmapdata object doesn't clean itself(By JIT). You need to dispose it manually. Some programmers return a bitmapdata object from a method and forget. For safe practice, if a method get a bitmapdata object as a parameter, don't forget to remove it, if it is unnecessary.

Other safe practices are to optimize loops, reusability and other things that you better know and would already practicing. 

In later posts, I'll share my other programming experiences.

See y then! [Forget about my spelling mistakes as I am not a regular writer] 

To comment for this article click this link.  

Comments
Add New Search
sfg  - done     |59.90.15.xxx |2010-02-21 20:14:16
fuck off
Medush9  - avtoresso.ru     |188.40.160.xxx |2010-06-26 12:55:52
? ??? ???????? ???????? ??????: ?????? ? ?????, ? ??????, ? ????!
Snyalovega8  - sibavtosnab.ru     |188.40.160.xxx |2010-06-27 17:02:51
???????, ??? ???? ????????……!!!! ? ?????? ???? ?? ???? ??? ???? ???????? ???????
?????!!!!
?????? ??????  - hopewarez.ru     |188.40.160.xxx |2010-06-29 21:32:03
??????? ?????? ?????!!! ????????????? ??????? ??? ?????? ?????…
Nataliaepp4  - zil-katalog.ru     |188.40.160.xxx |2010-07-01 17:47:34
???? ?? ???? ?????? ???? ?? ?????? ?? ?????
Murzyatina1  - westkino.ru     |188.40.160.xxx |2010-07-02 10:39:37
???????, ????? ????????? ?????????.
Ryndinalex2  - airsoftwar.ru     |188.40.160.xxx |2010-07-03 10:45:17
?????? ????? ? ????????
Mkskor8  - steamboilers.ru     |188.40.160.xxx |2010-07-04 11:11:56
????? ? ?? ??????????
????????? ?????  - oknakaifspb.ru     |188.40.160.xxx |2010-07-05 02:13:59
???????, ?????????)))
Victoryanna5  - vipseria.ru     |188.40.160.xxx |2010-07-05 19:06:39
???)??????? ??? ?????
Gaaalu3  - glamurplus.ru     |188.40.160.xxx |2010-07-06 22:47:44
? ????? ????????, ?? ???? ??? ???????? ?????????!
Elenalob2  - glamurplus.ru     |188.40.160.xxx |2010-07-07 16:21:27
? ??? ??? ???? ???????
???????? ????????  - alkoshot.ru     |188.40.160.xxx |2010-07-08 07:00:18
??????? ????, ??????? ??????.
Alfanis7  - tv56.ru     |188.40.160.xxx |2010-07-08 21:44:54
?????????, ??? ?????? ????? iPhone? ????? ?? ???? ????? ? ??????. ????????? ? ???? ???? ? ?????? ?? ?????? ???????????
?? ?????. ??? ?????
Acampo9  - tv56.ru     |188.40.160.xxx |2010-07-09 10:31:53
?????? ?????? ?? ???? ?????
???????? ?????  - rusvipa.ru     |188.40.160.xxx |2010-07-17 04:37:45
??? ???? ????????? ????? ?????????
Nixyz3  - 27hyperion.ru     |188.40.160.xxx |2010-07-19 16:14:42
??? ???????????.????? ??????? ??? ??????????????? ???, ????????????? ? ?????? ? ??????? ??????????????
(????????????, ?????????? ????) ? ??????????? ???????????. ??? ?????
?????? ??? ???????? ??? ????????? ????????????.
Nm5cec4  - dlmobile.ru     |188.40.160.xxx |2010-07-22 02:40:17
??? ?????????. ???
????????? ?? ??? ???????
Timonama5  - innohomes.ru     |188.40.160.xxx |2010-07-24 02:16:03
?? ??! ?????????? ??? ??????????! ?? ???????? ?????????
Systemofadownzw6  - kapc-shop.ru     |188.40.160.xxx |2010-07-24 22:31:10
???-?? ???????? ? ???? ??? ??? ?? ?????? ?? ???????!
Roxyrayan8  - my1school.ru     |188.40.160.xxx |2010-07-25 11:51:23
????? ??????
Ladiclear4  - dengibanki.ru     |188.40.160.xxx |2010-07-26 00:39:57
???????. ????????? ? ????????
Crows7  - dush2-nov.ru     |188.40.160.xxx |2010-07-26 11:31:06
?? ??? ? ???????? ?? ??????, ??????? ??? ???????.
???????? ???????????  - 27hyperion.ru     |188.40.160.xxx |2010-07-27 11:43:41
??? ???? ! ???? ????? ?? ??????????? !
????? ????? ??? ??????, ????? ??? ???? ??????? ??????? ??
?????? ??????? ? ???????? ??? ???? ? ????? ????? ??????…..
Rork9  - ikosmetsalon.ru     |188.40.160.xxx |2010-07-28 09:34:24
? ? ???? ????????? ????????. ??????? ???????!
Marysel5  - scenekid.ru     |188.40.160.xxx |2010-08-06 16:57:36
???????? ???????! ???? ???? - ?????!!!
Carima2  - okon-line.ru     |188.40.160.xxx |2010-08-08 12:26:30
???????, ???? ????????????? ??????? ??????? ? ?? ????, ???? ??? ??????????.
Turarkhan1  - monochrome-factor.ru     |188.40.160.xxx |2010-08-09 20:44:33
?? ?? ?????????? ???, ???? ??? ???????? ????
Chakoff1  - internetglobus.ru     |188.40.160.xxx |2010-08-13 13:59:29
?????? - ??????? ? ???????!!
??????? ????  - 1shop-life-best.ru     |188.40.160.xxx |2010-08-14 16:51:26
? ???? ??? ???? ? ????? ?????????? ?????????
?????? ?????  - system-shock.ru     |188.40.160.xxx |2010-08-16 07:51:44
??? ???????? ???? ?????, ?????????? ??????????)
Nm04134  - tutorialmagazine.ru     |188.40.160.xxx |2010-08-17 10:49:19
??????? +10
Blondyl7  - mypda-zverek.ru     |188.40.160.xxx |2010-08-19 08:26:07
??????? ??????????? ? ????, ??????? ? ??? ??????? ?? ????? ?????? - ????????
???????????!
???????? ?????  - pan-stroinn.ru     |188.40.160.xxx |2010-08-23 15:01:33
???? ???? ???? ?????, ?? ?????? ?????? ?????????, ? ??? ??????? ? ???? ???????!
Chramtcova1  - pan-stroinn.ru     |188.40.160.xxx |2010-08-24 10:07:48
????? ??????????
Fgvdes9  - lublyugotovit.ru     |188.40.160.xxx |2010-08-25 01:20:14
???? ??????? ??? ??????
????????? ????  - handpk.ru     |188.40.160.xxx |2010-08-25 12:24:21
??????? ?? ??????????? ??????!
Devilevo3  - new-gate.ru     |188.40.160.xxx |2010-08-26 12:57:18
???????, ??? ???? ????????……!!!! ? ?????? ???? ?? ???? ??? ???? ???????? ???????
?????!!!!
abercrombie  - Lic     |220.73.161.xxx |2010-08-31 17:32:02
Pregnancy is an exciting time full of hope Abercrombie and Fitch and excitement. It can also be an overwhelmingly Abercrombie self-conscience time as well, as your body is pregnant Abercrombie Sale does not mean you have to wear drab clothing Cheap Abercrombie and this is what a maternity clothes works to prevent.You can now breathe
a little easier Abercrombie outlet with the knowledge that you can find clothes that fit you appropriately buy Abercrombie through changing like it never has before! Maternity clothes are available
Abercrombie clothing for you to help you look and feel beautiful throughout abercrombie & fitch your pregnancy. You can find a number of companies who produce garments Abercrombie kids for pregnant women that are not only comfortable Abercrombie Outerwears but fashionable as well.You will find that clothes that cater Abercrombie & Fitch Outerwears to the pregnant body are usually created in order to grow with t...
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Thursday, 13 November 2008 21:07 )
 
Copyright © 2010 pravinranjan.com. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.