[odb-users] weak pointer gets erased during update

Jeff Waller truthset at gmail.com
Mon Jul 29 10:10:06 EDT 2013


Hi Boris,

In order to keep the example short I did not show all the details,
sorry abut that.  Yes I was/am using a session object, the pointed to
object defaultDomain is still in scope (or at least that's an object that
gets constructed by the same database information as that which
gets (I assume) constructed and then destructed in the
function call createAccount; they both have the same id anyway.

Perhaps my error is to pass to the function createAccount a character
pointer (the domain name) rather than a shared_ptr<Domain>.  But
then I thought that session would save me from worrying about that;
which goes back to the first statement which you have highlighted.

On Jul 29, 2013, at 6:09 AM, Boris Kolpackov wrote:

> Hi Jeff,
> 
> Jeff Waller <truthset at gmail.com> writes:
> 
>> It's not quite clear to me when a weak_ptr can become invalid.
> 
> This is not really an ODB-specific question. In a few words, if
> there is no shared_ptr somewhere in the application pointing to
> the same object, then weak_ptr is invalid.
> 
> When loading object from the database, session should be used
> in order to correctly load relationships with weak pointers.
> When, however, constructing the object model from scratch (
> which, it seems, is what you are doing in your example), it
> is your reponsibilty to make sure that objects pointed-to by
> weak_ptr's are still valid.
> 
> Boris



More information about the odb-users mailing list