<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Feb 21, 2017 at 4:24 PM Greg Clayton via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Feb 21, 2017, at 9:10 AM, Zachary Turner via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="gmail_msg" target="_blank">lldb-dev@lists.llvm.org</a>> wrote:</div><br class="m_-2156000030404542274Apple-interchange-newline gmail_msg"><div class="gmail_msg">No comments on this specifically, but +1 to reducing shared_ptr usage in general.  We use way too many, and often it feels like shared_ptr is used as a way to avoid having to think about ownership, which leads to more problems than it solves imo<br class="gmail_msg"></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">We do a pretty good job of using shared pointers where they are needed, so I don't agree with the above statement. We have strong memory models in LLDB and certain things need to keep certain things alive. LLVM is quite the wild west with regard to memory management, so I don't want to base any changes on it. We just need to use std::weak_ptr when needed. There should be no two items that contain strong references to each other. </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">In general think about what should keep things alive. If I have a SBModule variable, I should expect that it won't let my module go away. If I have a SBTarget, I would expect it to keep the target around as long as I have a reference. Things that belong to any of these items, like breakpoints, watchpoints, compile units, functions, shouldn't keep the module or target around.</div></div></blockquote><div><br></div><div>Agree with all of this, but I think most of the time you only need 1 thing keeping an object alive (i.e. unique_ptr), and from there you can just hand out references.  In the case where an object might die while a reference is outstanding, then a lot of times I think the design can be adjusted so that doesn't happen, but when it's still necessary, you can store a shared_ptr and vend out weak_ptrs.  You don't need everything in the system keeping everything else alive.</div><div><br></div><div>I'm speaking from a purely general standpoint, I haven't done a deep dive into LLDB to see where this does / doesn't apply, but in my experience shared_ptrs are one of the most overused things in all of C++.  So when I see a lot of them, I just default to "I bet these can be reduced significantly"</div></div></div>