1. 被删除对象在外部的所有引用一定要被删除干净才能被系统当成垃圾回收处理掉;
2. 父对象内部的子对象被外部其他对象引用了,会导致此子对象不会被删除,子对象不会被删除又会导致了父对象不会被删除;
3. 如果一个对象中引用了外部对象,当自己被删除或者不需要使用此引用对象时,一定要记得把此对象的引用设置为null;
4. 本对象删除不了的原因不一定是自己被引用了,也有可能是自己的孩子被外部引用了,孩子删不掉导致父亲也删不掉;
5. 除了引用需要删除外,系统组件或者全局工具、管理类如果提供了卸载方法的就一定要调用删除内部对象,否则有可能会造成内存泄露和性能损失;
6. 父对象立刻被删除了不代表子对象就会被删除或立刻被删除,可能会在后期被系统自动删除或第二次移除操作时被删除;
7. 如果父对象remove了子对象后没有清除对子对象的引用,子对象一样是不能被删除的,父对象也不能被删除;
8. 注册的事件如果没有被移除不影响自定义的强行回收机制,但有可能会影响正常的回收机制,所以最好是做到注册的事件监听器都要记得移除干净。
9. 父对象被删除了不代表其余子对象都删除了,找到一种状态的泄露代码不等于其他状态就没有泄露了,要各模块各状态逐个进行测试分析,直到测试任何状态下都能删除整个对象为止。
内存泄露举例:
1. 引用泄露:对子对象的引用,外部对本对象或子对象的引用都需要置null;
2. 系统类泄露:使用了系统类而忘记做删除操作了,如BindingUtils.bindSetter(),ChangeWatcher.watch()函数时候完毕后需要调用ChangeWatcher.unwatch()函数来清除引用 ,否则使用此函数的对象将不会被删除;
类似的还有MUSIC,VIDEO,IMAGE,TIMER,EVENT,BINDING等。
3. 效果泄露:当对组件应用效果Effect的时候,当本对象本删除时需要把本对象和子对象上的Effect动画停止掉,然后把Effect的target对象置null; 如果不停止掉动画直接把 Effect置null将不能正常移除对象。
4. SWF泄露:要完全删除一个SWF要调用它的unload()方法并且把对象置null;
5. 图片泄露:当Image对象使用完毕后要把source置null;(为测试);
6. 声音、视频泄露: 当不需要一个音乐或视频是需要停止音乐,删除对象,引用置null;
内存泄露解决方法:
1. 在组件的REMOVED_FROM_STAGE事件回掉中做垃圾处理操作(移除所有对外引用(不管是VO还是组件的都需要删除),删除监听器,调用系统类的清除方法)
先remove再置null, 确保被remove或者removeAll后的对象在外部的引用全部释放干净;
2. 利用Flex的性能优化工具Profile来对项目进程进行监控,可知道历史创建过哪些对象,目前有哪些对象没有被删除,创建的数量,占用的内存比例和用量,创建过程等信息;
总结:关键还是要做好清除工作,自己设置的引用自己要记得删除,自己用过的系统类要记得做好回收处理工作。 以上问题解决的好的话不需要自定义强制回收器也有可能被系统正常的自动回收掉。
转自:
http://xinsync.xju.edu.cn/index.php/archives/3298
text-overflow:ellipsis这个属性的确是好用,可惜FF不支持
偶尔想到用after伪类类实现模拟

Code
* {margin:0; padding:0; list-style:none; }
body{
font-family: 宋体;
font-size: 12px;
}
#box {
width:200px;
border:1px green solid;
}
#box span{
display:block;
overflow:hidden;
float:left;
width:156px;
*width:180px;/*for IE*/
white-space:nowrap;
text-overflow:ellipsis;/*just for IE */
}
#box:after {/*for FF*/
content:"
";
}

Code
<div id="box"><span class="text">我是文字,我很长很长很长很长很长很长很长很长很长</span></div>
虽然这个方法是瞎了点,但还是有点意思;
转载自:http://www.cnblogs.com/rayking/archive/2008/09/03/1282466.html
FireBug 是一个非常实用的JavaScript以及DOM查看调试工具,是 Firefox 的一个插件。使用 FireBug 调试 AJAX 应用非常方便,终于可以告别 alert 时代了!
Console Logging 函数FireBug 为所有 Web 页面提供了一个 console 对象。这个对象有以下函数:
Logging 基础
console.log("message" [,objects]) - 将一个字符串打印到控制台。字符串可以包含任何“String Formatting”小节描述的模式。字符串后面的对象应该用来取代之前字符串中的模式。(译者注:大家用过C里面 printf 吧,效果基本是一样的。)
Logging 等级通常根据不同的等级来区分Logging的严重程度是很有帮助的。FireBug 提供了4个等级。为了达到视觉分离的效果,这些函数与 log 不同的地方就是它们在被调用的时候会自动包含一个指向代码行数的链接。
console.debug("message" [,objects]) - 记录一个 debug 消息。
console.info("message" [,objects]) - 记录一个信息.
console.warn("message" [,objects]) - 记录一个警告.
console.error("message" [,objects]) - 记录一个错误.
断言断言是一条确保代码规则的非常好的途径。console 对象包含了一系列各种类型的断言函数,并且允许你编写自己的断言函数。
console.assert(a, "message" [,objects]) - Asserts that an a is true.
console.assertEquals(a, b, "message" [,objects]) - Asserts that a is equal to b.
console.assertNotEquals(a, b, "message" [,objects]) - Asserts that a is not equal to b.
console.assertGreater(a, b, "message" [,objects]) - Asserts that a is greater than b.
console.assertNotGreater(a, b, "message" [,objects]) - Asserts that a is not greater than b.
console.assertLess(a, b, "message" [,objects]) - Asserts that a is less than b.
console.assertNotLess(a, b, "message" [,objects]) - Asserts that a is not less than b.
console.assertContains(a, b, "message" [,objects]) - Asserts that a is in the array b.
console.assertNotContains(a, b, "message" [,objects]) - Asserts that a is not in the array b.
console.assertTrue(a, "message" [,objects]) - Asserts that a is equal to true.
console.assertFalse(a, "message" [,objects]) - Asserts that a is equal to false.
console.assertNull(a, "message" [,objects]) - Asserts that a is equal to null.
console.assertNotNull(a, "message" [,objects]) - Asserts that a is not equal to null.
console.assertUndefined(a, "message" [,objects]) - Asserts that a is equal to undefined.
console.assertNotUndefined(a, "message" [,objects]) - Asserts that a is not equal to undefined.
console.assertInstanceOf(a, b, "message" [,objects]) - Asserts that a is an instance of type b.
console.assertNotInstanceOf(a, b, "message" [,objects]) - Asserts that a is not an instance of type b.
console.assertTypeOf(a, b, "message" [,objects]) - Asserts that the type of a is equal to the string b.
console.assertNotTypeOf(a, b, "message" [,objects]) - Asserts that the type of a is not equal to the string b.
测量(Measurement)下面的一些函数可以让你方便的测量你的一些代码。
console.trace() - 记录执行点的堆栈信息。
console.time("name") - 根据 name 创建一个唯一的计时器。
console.timeEnd("name") - 根据 name 停止计时器,并且记录消耗的时间,以毫秒为单位。
console.count("name") - 记录该行代码执行的次数。
字符串格式化所有 console 的 logging 函数都可以通过以下模式格式化字符串:
%s - 将对象格式化为字符串。
%d, %i, %l, %f - 将对象格式化为数字。
%o - 将对象格式化成一个指向 inspector 的超链接。
%1.o, %2.0, etc.. - 将对象格式化成包含自己属性的可交互的表格。
%.o - 将对象格式化成具有自身属性的一个数组。
%x - 将对象格式化成一个可交互的 XML 树形结构。
%1.x, %2.x, etc.. - 将对象格式化成一个可交互的 XML 数型结构,并且展开 n 层节点。
如果你需要一个真实的 % 符号,你可以通过一个转移符号就像这样 "\%"。
命令行函数内建的命令行函数可以通过以下命令行使用:
$("id") - document.getElementById() 的简写。(译者注:跟 prototype.js 学来的吧?)
$$("css") - 返回一个符合 CSS 选择器的元素数组。
$x("xpath") - 返回一个符合 XPath 选择器的元素数组。
$0 - 返回最近被检查(inspected)的对象。
$1 - 返回最近被检查(inspected)的下一个对象。
$n(5) - 返回最近被检查的第n个对象。
inspect(object) - 将对象显示在 Inspector 中。
dir(object) - 返回一个对象的属性名数组。(译者注:跟 Python 学的?)
clear() - 清除控制台信息。
//显示属性
display
list-style
position
float
clear
//自身属性
width
height
margin
padding
border
background
//文本属性
color
font
text-decoration
text-align
vertical-align
white-space
other text
content
IE6,IE7,FF3测试通过

CSS
* {
margin:0;
padding:0;
list-style:none;
}
#vertical_box {
width:100%;
display:table;
border:1px red solid;
height:400px;
/*针对IE的hack*/
*position:relative;
}
#vertical_box_sub {
display: table-cell;
vertical-align: middle;
/*针对IE的hack*/
*position:absolute;
*top:50%;
}
#vertical_box_container {
font-family:"宋体";
border:1px green solid;
/*针对IE的hack*/
*position:relative;
*top:-50%;
margin:0 auto;
width:200px;
}

HTML
<div id="vertical_box">
<div id="vertical_box_sub">
<div id="vertical_box_container">
<p>我是居中的文字</p>
<p>我居中</p>
<p>你也居中</p>
<img src="http://www.adobetutorialz.com/Advertising/W3Markup.jpg" border=0 alt="" title="">
</div>
</div>
</div>
需要引入
import flash.external.ExternalInterface;
一、ActionScript调用JavaScript的方法
这里要用到ExternalInterface类的call方法
ExternalInterface.call(functionName:String,...arguments):*
fuctionName:要调用的JavaScript函数名
arguments:参数,可选
1.不带参数的情况

JavaScript
function Show() {
alert("I am a func!");
}

ActionScript
//直接用一条语句调用
ExternalInterface.call("Show");
2.带参数的情况

JavaScript
function Show(message) {
alert(message);
}

ActionScript
ExternalInterface.call("Show","I am a message from AS");
另外,也可以用getURL方法来调用
getURL("javascript:show('i am a message from as)","_self");
二、JavaScript调用ActionScript的方法
这要用到ExternalInterface类的addCallback方法
ExternalInterface.addCallback( functionName:String, closure:Function):void
functionName:要注册的函数名
closure:对应的执行函数

ActionScript
ExternalInterface.addCallback("Show",OnShow);
private function OnShow(message:String):string{
return message;
}

JavaScript
function thisMovie(movieName){
if(navigator.appName.indexOf("Microsoft") != -1){
return window[movieName];
}else{
return document[movieName];
}
}
function CallAS( ) {
thisMovie("ViewLesson").Show("i am a message from js");//ViewLesson是flash媒体的ID
}

HTML
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="ViewLesson" width="100%" height="100%"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="ViewLesson.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="ViewLesson.swf" quality="high" bgcolor="#869ca7"
width="100%" height="100%" name="ViewLesson" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
function Dog()
{
this.name = "普通的狗";
this.wow = function()
{
alert(this.name + " is wowing!!");
}
this.sleep = function()
{
alert(this.name + " is sleep");
}
}
function FlyingDog()
{
this.name = "会飞的狗";
this.wow = function()
{
alert(this.name + " is flying and wowing");
}
}
FlyingDog.prototype = new Dog();
flyingdog = new FlyingDog();
flyingdog.wow();
flyingdog.sleep();