Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I used to agree with Rust approach, assuming the compiler does dataflow analysis to minimize needless refcounting.

Now that the refcounting is also moved to a library, I am not sure.

Or are those types known to the compiler and the respective optimizations applied?



They fall out automatically from move semantics, a reference count only occurs on an explicit clone call:

  fn just_a_ref(x: &T) { ... }
  fn rc_by_val(x: Rc<T>) { ... }
  fn rc_by_ref(x: &Rc<T>) { ... }

  let some_rc_pointer: Rc<T> = ...;

  just_a_ref(&*some_rc_pointer); // no ref counting
  rc_by_ref(&some_rc_pointer); // no ref counting

  rc_by_val(some_rc_pointer.clone()); // ref count incremented

  // last use of a value (statically guaranteed that 
  // some_rc_pointer is never used again):
  rc_by_val(some_rc_pointer); // no ref counting


Thanks for the clarification.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: