Owned, allocate a class instance following this
var myOwnedObject = new Owned(new MyClass(...));
When myOwnedObject goes out of scope, the class instance it refers to will be deleted.
It is an error to copy initialize from myOwnedObject or to assign
it to another
The ways in which
Owned may be used are currently limited.
Copy-initialization, assignment, and in intent are expected to work.
However, it is an error to use a
Owned in a way that causes the
compiler to add an implicitly copy, such as by returning a
that was passed by reference.
Owned arguments with const in intent do not work yet.
Owned(p, type t = p.type)
It is an error to directly delete the class instance while it is managed by a
Arguments: p -- the class instance to manage. Must be of class type.
Owned(ref src: Owned, type t = src.t)
Copy-initializer. Creates a new
Ownedthat takes over ownership from src. src will refer to nil after this call.
proc ref clear()
Ownedso that it stores nil. Deletes the previously managed object, if any.
proc ref retain(newPtr: p.type )
Change the instance managed by this class to newPtr. If this record was already managing a non-nil instance, that instance will be deleted.
proc ref release(): p.type