Skip to content

Instantly share code, notes, and snippets.

@jpf91
Created July 25, 2011 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpf91/1103866 to your computer and use it in GitHub Desktop.
Save jpf91/1103866 to your computer and use it in GitHub Desktop.
detach()
{
if (!RefCounted._store) return;
assert(RefCounted._store._count > 0);
if (--RefCounted._store._count)
{
debug(RefCounted) if (RefCounted.debugging)
writeln(typeof(this).stringof,
"@", cast(void*)RefCounted._store,
": decrement refcount to ", RefCounted._store._count);
RefCounted._store = null;
return;
}
debug(RefCounted) if (RefCounted.debugging)
{
write(typeof(this).stringof,
"@", cast(void*)RefCounted._store, ": freeing... ");
stdout.flush();
}
// Done, deallocate
assert(RefCounted._store);
clear(RefCounted._store._payload);
if (hasIndirections!T && RefCounted._store)
GC.removeRange(RefCounted._store);
free(RefCounted._store);
RefCounted._store = null;
debug(RefCounted) if (RefCounted.debugging) writeln("done!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment