public const id:Number
运行时版本: | AIR 1.0 Flash Player 9.0.115.0 |
与 NewObjectSample 的标识号相匹配的唯一标识号。仅适用于 Flash Player 调试版。
另请参见
public const size:Number
运行时版本: | AIR 1.0 Flash Player 9.0.115.0 |
DeleteObjectSample 对象在删除之前的大小。仅适用于 Flash Player 调试版。
另请参见
下面的示例使用 Sample 对象
s
的
stack
和
time
属性来收集内存样本。该样本包含 NewObjectSample 对象(
newSamples
数组)、DeleteObjectSample 对象(
delSamples
数组)和 CPU 内存样本对象(
cpuSamples
数组)。若要使用内存设置,需要安装 Flash Player 调试版 9.0.115.0 或更高版本。
package
{
import flash.sampler.*
import flash.system.*
import flash.utils.*
import flash.display.Sprite
public class sampleTypes extends Sprite
{
var b:Boolean = true
public function sampleTypes() {
flash.sampler.startSampling();
for(var i:int=0;i<10000;i++)
new Object();
var cpuSamples:Array=[];
var newSamples:Array=[];
var delSamples:Array=[];
var ids:Array=[]
var lastTime:Number=0;
for each(var s:Sample in getSamples()) {
assert(s.time > 0); // positive
assert(Math.floor(s.time) == s.time, s.time); // integral
assert(s.time >= lastTime, s.time + ":" + lastTime); // ascending
assert(s.stack == null || s.stack is Array)
if(s.stack) {
assert(s.stack[0] is StackFrame);
assert(s.stack[0].name is String);
}
if(s is NewObjectSample) {
var nos = NewObjectSample(s);
assert(s.id > 0, s.id);
assert(s.type is Class, getQualifiedClassName(s.type));
newSamples.push(s);
ids[s.id] = "got one";
} else if(s is DeleteObjectSample) {
var dos = DeleteObjectSample(s);
delSamples.push(s);
assert(ids[dos.id] == "got one");
} else if(s is Sample)
cpuSamples.push(s);
else {
assert(false);
}
lastTime = s.time;
}
trace(b)
trace(newSamples.length > 0)
trace(cpuSamples.length > 0)
trace(delSamples.length > 0)
}
private function assert(e:Boolean, mess:String=null):void {
b = e && b;
if(true && !e) {
if(mess) trace(mess);
trace(new Error().getStackTrace());
}
}
}
}