[odb-users] Memory leaks when using odb::session

Michaël Martín Moro michael at unetresgrossebite.com
Mon Sep 19 09:28:57 EDT 2016


Thanks for taking care of me !

Most of the objects were using shared_ptr already, but I've noticed that I 
forgot to specify the pointer type on my views. So that helped !

After a much closer inspection, I've realized that this leak happens because 
the odb::database object is not deleted properly.

I've been able to reproduce the same kind of memory leaks on a small 
project... but in that project, the issue only happens if odb::database isn't 
deleted after the odb::session.

Considering the way it's stored (thread_local std::unique_ptr<odb::database>), 
it's a bit absurd that odb::database doesn't get deleted in my application... 
but the evidence is there, so I'll just assume that's what happens. Anyhow, 
the situation raises more questions.

Does that mean that, between two requests, I should remove the odb::database 
object ? Does it mean that, as long as I don't remvoe the odb::database 
object, there's a cache stored somewhere ?

Because I definitely do not want that. And yet, I do not want to disconnect 
and re-connect the database at every query.

On domingo, 18 de septiembre de 2016 23:43:11 (CEST) you wrote:
> Hi,
> 
> Michael Martín Moro <sexymimi64 at gmail.com> writes:
> > I had to use odb::session to get a bidirectional relationship working. I
> > noticed that whenever there's an odb::session active in a query, I end up
> > with a lot of memory leaks pointing at memory allocated through odb.
> 
> You are probably using raw pointers for your objects. Use std::shared_ptr
> instead (Section 3.3, "Object and View Pointers" in the manual).
> 
> Boris





More information about the odb-users mailing list