I tried to deal with WebToolkit and write my application by examples. But after starting work with the base, the problems started and the last and not solved by me is a memory leak after transferring the model to the view and view of the table of elements.

manTable = new Wt::WTable(); database *wsedb = new database(); wsedb->dbInit(); ... manView = new Wt::WTableView(); manView->setModel(wsedb->manModel); manTable->elementAt(1,0)->addWidget(manView); 

I can not understand how to solve this problem, at all. It seems that the types are declared correctly, all the headers are connected, in the examples of developers the work goes the same. Sorts: database.h:

 #ifndef DATABASE_H #define DATABASE_H #include<Wt/Dbo/backend/Sqlite3> #include<Wt/Dbo/Dbo> #include <Wt/Dbo/Session> #include <Wt/Dbo/QueryModel> #include <Wt/WApplication> #include "manuals.h"//map clases namespace dbo = Wt::Dbo; class database { public: database(); dbo::Session SessionW; dbo::QueryModel<dbo::ptr<manuals>> *manModel; void dbInit(); void dbTrans(); void addMan(); }; #endif // DATABASE_H 

database.cpp:

 #include "database.h" using namespace Wt; database::database() { } void database::dbInit() { dbo::backend::Sqlite3 wseDB=WApplication::instance()->appRoot() + "wse.db"; SessionW.setConnection(wseDB); wseDB.setProperty("show-queries", "true"); SessionW.mapClass<manuals>("manuals"); manModel=new dbo::QueryModel<dbo::ptr<manuals>>(); dbo::Transaction trans(SessionW); try{ SessionW.createTables(); Wt::log("info") << "Database created"; } catch (...) { Wt::log("info") << "Using existing database"; } trans.commit(); manModel->setQuery(SessionW.find<manuals>()); manModel->addAllFieldsAsColumns(); dbo::Transaction trans1(SessionW); Wt::Dbo::collection<Wt::Dbo::ptr<manuals> > a=SessionW.find<manuals>().orderBy("date desc"); trans1.commit(); } 
  • You forgot to delete manModel in database destructor. And why manModel in the heap, and not on the stack? - Cerbo
  • I try to make it work for now, and then refactor. Only now I noticed that the destructor is not at all in the class. - Lenny Marks
  • It is difficult to help you, leaks at a distance are not treated! Try to disconnect the code in chunks and check for leaks, gradually narrowing the search area. - Cerbo
  • No need to disable pieces of code. Try in the debugger to find the place where the crash occurs. With a high probability, these are places of reference to pointers to objects of classes that you selected using the new operator. Put breakpoints there, go, look. Find, referring to which pointer causes an error. Then you figure out where you are changing this pointer. Well, Cerbo correctly noted that it is more logical to create an object on the stack. Or use smart pointers. - user1056837

1 answer 1

For catching memory leaks under Linux is a great tool - Valgrind. The closest IDE with Valgrind support is Qt Creator.

It searches for both memory leaks and pointers to pointers.