weakReference

Convenience function that returns a WeakReference!T object for target.

@safe
weakReference
(
T
)
()

Examples

t
{
	auto weak = weakReference(new Object());
	// ...
	if(auto obj = weak.target)
	{
		// Still alive! Let's kill it by hands.
		destroy(obj);
		assert(!weak.alive && !weak.target);
t
{
	auto weak = weakReference(&(new Object()).toString);
	// ...
	if(auto del = weak.target)
	{
		// It's alive! Let's check and kill it by hands.
		assert(del() == "object.Object");
		destroy(cast(Object) del.ptr);
		assert(!weak.alive && !weak.target);

Meta