Lots and lots of things are caching a BufferView * or a Buffer *. To name a few: InsetFormulaBase (BufferView *) InsetCite (Buffer *) GraphicsLoader (BufferView *, cached for 2 secs then used).
Moreover, InsetGraphics and InsetInclude both are using current_view because they don't cache but should. In the case of InsetInclude that's preview related so it's not yet in cvs. Clearly when we move to multiple / changing BufferViews this is going to lead to nasty problems. Lars has mentioned using boost::weak_ptr in just such a context and I'd like to do so here. From the boost docs ========================================= http://www.boost.org/libs/smart_ptr/weak_ptr.htm The weak_ptr class template stores a pointer to an object that's already managed by a shared_ptr. When the object last shared_ptr to the object goes away and the object is deleted, all weak_ptr objects have their stored pointers set to 0. ========================================= I'd like, therefore, to change the LyXView store public: /// return the current buffer view BufferView * view() const { return bufferview_,get(); } + /// weak_ptr.get() is reset to 0 automatically when bufferview_ is killed. + boost::weak_ptr<BufferView> const cachablePtr() const { + return boost::weak_ptr<BufferView>(bufferview_); + } private: /// view of a buffer. Eventually there will be several. - boost::scoped_ptr<BufferView> bufferview_; + boost::shared_ptr<BufferView> bufferview_; and to make it accessible through BufferView: boost::weak_ptr<BufferView> const BufferView::cachablePtr() const { return pimpl_->owner_->cachablePtr(); } Then if things want to cache a BufferView * then they can do so safely. What do you think? Angus ps, when LyXView stores multiple BufferViews, we'd perhaps have boost::weak_ptr<BufferView> const cachablePtr(BufferView *) const; but that is for the future... A