Are shared_ptr and link counting in iOS the same idea?

I'm not very good at C ++ or iOS, so I just wonder if iOS link counting works basically the same in shared pointers and in NSObject?

+4
source share
2 answers

From what I'm compiling here , using ARC is very similar to using std::shared_ptr (strong pointers) and std::weak_ptr (weak pointers).

Break the first and avoid the last. Anyway, prefer std::unique_ptr if you can.

(Also, I'm somewhat surprised that you had to specify pointers manually when programming for iOS. In the 21st century.)

+2
source

I am not very good at C ++, so I may not be quite right about shared_ptr, but for me they are not like each other. Obj-C has two options. Manual memory management - you manually increase and decrease the number of links for your objects, there is no magic here. And the new ARC, which is mainly a compile-time function, and shared_ptr is just a runtime implementation.

0
source

Source: https://habr.com/ru/post/1435999/


All Articles