Non-GC Memory Resource Management [DRAFT]
Created at 2016-09-25T07:30:03.000Z

Keywords

  • scope
    • destructor will be called when a variable gets out of scope
  • RAII (Resource Acquisition is Initialization)
  • smart pointer
    • unique_ptr in c++ (how's implementation? is it needed to be implemented inside of runtime?)

shared, weak pointer example

weak_ptr wp;

f () : void = 
  shared_ptr p = ...
  wp = p
  ... # here p will be destructed when f gets out because of scope

wp.lock() # check validity somewhere else

but, FP-like algebraic data type transformation cannot be achieved within this limitted way ? like, creating object (i.e. allocate memory) inside of function and return it? not really, because such an object anyway will be destructed when the variable referencing it gets out of scope.

  • find example where memory leaks
    • of course, it happens if several initialized (heap-allocated) objects are assigned to single variable.
    • but that's not SSA (static single assignment) style programming. I want to find other example.

Reference