TMI: Destructors
May. 15th, 2012 10:20 pmYesterday and today, I worked on adding destructors to classes. A destructor is a method that can't be named directly, to which the compiler inserts a call whenever the memory for the class is about to be freed (so, whenever its reference count becomes zero). Here's a super simple example of a class with a destructor:
class shrinky_pointer { let i: @@mut int; fn look_at() -> int { ret **(self.i); } new(i: @@mut int) { self.i = i; } drop { **(self.i) -= 1; } }( Read more... )