Manually force Rc to increment counter


#1

I realize this is a terrible idea and leads to memory leaks.

However, I’m in a weird situation where I absolutely want to unsafely increment the Ref count of a Rc by 1.

How can I unsafely do this?


#2

Answer: Rc::into_raw()


#3

Alternatively: std::mem::forget(some_rc.clone()). Calling clone on an Rc just increments the count and forget prevents Rc's drop implementation from decrementing it again.