[odb-users] Problem with session cache and weak_ptr

Boris Kolpackov boris at codesynthesis.com
Tue Apr 26 09:59:18 EDT 2016


Hi Marcel,

Marcel Nehring <mne at qosmotec.com> writes:

> I think I discovered a problem with ODB's object loading mechanism in
> conjunction with weak_ptr. I am using a custom session implementation so
> that my session's cache behaves a bit different from ODB's. Therefore it
> might happen, that I have an object in my cache that references another
> object via a weak_ptr member. If the pointee goes out of scope so that the
> weak_ptr expires I run into problems when loading the pointing object. The
> pointing object is still in my cache, so ODB correctly gets the instance
> from there. I then see, that ODB asks the cache for the (already expired)
> pointee. The cache cannot provide it, so I see ODB inserting it into the
> cache. After loading finishes, however, the weak_ptr member is still
> empty. Both objects correctly exist in my cache but the link is
> missing/invalid. Looks like ODB does not (re)set the weak_ptr to the newly
> loaded instance.

Hm, that would be strange. Are you sure ODB is loading the same object
as the one containing the expired weak_ptr member? If it were a different
object, then that would explain the behavior you are observing.

Boris



More information about the odb-users mailing list