Talk:cpp/memory/weak ptr/weak ptr

ownership
It seems a little funny to use the word "ownership" with weak_ptr. I'd be concerned that people might confuse it with how e.g. a shared_ptr "owns" memory (and is responsible for cleaning it up). Are there any better words that might make that distinction clearer?


 * Perhaps "shares the ownership" on this page is not the best wording, but in general, weak_ptr certainly deals with object ownership intimately: it shares the control block. --Cubbi 06:01, 9 April 2012 (PDT)


 * That is certainly true. I guess I'd expect an object that owns a chunk of memory to be responsible for freeing that memory, which is why the word "ownership" scares me.   Perhaps one way out of this is to be more explicit: instead of "shares ownership", how about "shares a control block"? 166.137.136.121 15:12, 9 April 2012 (PDT)


 * We might as well describe everything relevant (shared_ptr, weak_ptr, make_shared/allocate_shared, enable_shared_from_this) in terms of control blocks. Although this is an implementation detail, it certainly makes it easier to discuss these things. A couple pictures would make it even better. --Cubbi 06:26, 11 April 2012 (PDT)


 * I would vote for a middle ground. Current wording is certainly a bit confusing, but writing the description in terms of the control block isn't a perfect solution too, because the standard doesn't specify such things. Maybe improving the current wording and then mentioning the control block would be the best of the two worlds? -- P12 07:27, 11 April 2012 (PDT)


 * Okay, I took a whack at this and changed "shares ownership" to "shares an object". Objections? Nate 05:58, 16 April 2012 (PDT)

Example in page about weak_ptr constructor doesn't actually demonstrate usage of constructor.
Perhaps I'm missing something, but it seems to me that the page is for constructors of weak_ptr, but the example only demonstrates use of assignment operator, and nowhere in the example is the usage of constructor for weak_ptr is demonstrated?

(Yes, technically default constructor is called at weak_ptr declaration, but that seems a weak example, no pun intended. A better example perhaps is of std::weakptr(const std::shared_ptr& r)) and how it behaves??

104.176.164.58 09:16, 31 March 2021 (PDT)