IDisposable in Unityscript?

Does anyone know the syntax for an IDisposable class in UnityScript? The C# ~ callback doesn't work.

Thanks,

-Aubrey

  • If you mean the finalizer (destructor) by "C# ~ callback", it is called at an seemingly arbitrary time after references to the object have been lost. So it gets called but maybe you expect them to behave differently.

  • There is a IDisposable interface in .NET. (System.IDisposable) that you can use in case you need to release unmanaged resources.

  • If you just want to destroy a script or a game object, use Destroy(scriptInstance); or Destroy(gameObject);

Points to remember:

  • Destructors are invoked automatically, and cannot be invoked explicitly.
  • Destructors cannot be overloaded. Thus, a class can have, at most, one destructor.
  • Destructors are not inherited. Thus, a class has no destructors other than the one, which may be declared in it.
  • Destructors cannot be used with structs. They are only used with classes.
  • An instance becomes eligible for destruction when it is no longer possible for any code to use the instance.
  • Execution of the destructor for the instance may occur at any time after the instance becomes eligible for destruction.
  • When an instance is destructed, the destructors in its inheritance chain are called, in order, from most derived to least derived.

I'm not sure what callback you're talking about, but an IDisposable class is just one that implements the IDisposable interface and has a public Dispose method:

public class MyClass : IDisposable
{
    public void Dispose()
    {
    }
}

Edit:

IDisposable isn't what you're looking for at all, you're wanting the finalizer syntax. Try this instead:

function Finalize()
{
}