package uk.co.bigroom.utils
{
import flash.utils.Dictionary;
/**
* Class to create a weak reference to an object. A weak reference
* is a reference that does not prevent the object from being
* garbage collected. If the object has been garbage collected
* then the get method will return null.
*/
public class WeakRef
{
private var dic:Dictionary;
/**
* The constructor - creates a weak reference.
*
* @param obj the object to create a weak reference to
*/
public function WeakRef(obj:*)
{
dic = new Dictionary(true);
dic[obj] = 1;
}
/**
* To get a strong reference to the object.
*
* @return a strong reference to the object or null if the
* object has been garbage collected
*/
public function get():*
{
for (var item:* in dic)
{
return item;
}
return null;
}
}
}
在這個類中,它們是如何表示弱引用和強引用的。弱引用和強引用
你能不能給我弱和強引用的定義。我無法得到。對不起 – Kevin 2010-05-06 12:27:06
@theband:請參閱我的更新。另外,您可能需要查看http://en.wikipedia.org/wiki/Reference_counting#Use_in_garbage_collection瞭解更多詳情。 – back2dos 2010-05-06 12:54:36
謝謝了更新 – Kevin 2010-05-07 12:49:58