SqlConnection的executeAndWait导致BB10上的内存泄漏
SqlConnection's executeAndWait causes memory leak on BB10
当我调用executeAndWait并且返回回复时,我看到堆内存增加了76KB。我不知道为什么会这样。如何清理此内存?我与 db 的连接创建如下,
bool DBHelper::checkConnection(bool isAsynch)
{
if(sqlConnector && dbFile->exists())
{
return true;
}
if (dbFile->exists())
{
sqlConnector = new SqlConnection(dbPath, "connect");
connect(sqlConnector, SIGNAL(reply(const bb::data::DataAccessReply&)), this,
SLOT(onLoadAsyncResultData(const bb::data::DataAccessReply&)));
return true;
}
return false;
}
对 executeAndWait 的调用在此函数中,
void DBHelper::execute (const QVariant &criteria,int id,bool isAsynch)
{
if (checkConnection(isAsynch))
{
if(!isAsynch)
{
DataAccessReply reply= sqlConnector->executeAndWait(criteria, id); // memory leak happens when the reply is found.
this->onLoadSynchResultData(reply);
}
}
}
文档链接在这里。
谢谢。
你确定这是内存泄漏而不是DataAccessReply
类的一些内部机制吗?您是否尝试过用valgrind或类似工具将其刺穿?
从您使用new
分配和后续分配中,我认为sqlConnector
的类型是指向某物的指针。虽然它可能不是您正在寻找的解决方案,但我建议使用一些智能指针类型,因为这些总是更防漏。
如果有兴趣,请参阅例如 boost::shared_ptr
或C++11 std::shared_ptr
取决于您可用的内容。
另外(在这里叫我迂腐)我不会使用if(sqlConnector)
即使它可能通过隐式强制转换来达到您的期望。我会显式使用if(sqlConnector != NULL)
(或类似的东西)并仔细检查sqlConnector
是否正确初始化(也显式地)。
相关文章:
- 从构造函数抛出异常时如何克服内存泄漏
- malloc() 可能出现内存泄漏
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 尽管遵循了规则,内存泄漏在哪里
- 为什么调用堆栈数组会导致内存泄漏
- 在简单示例中,Python3 + ctypes 回调会导致内存泄漏
- 使用模板类的自定义列表类型中的内存泄漏
- 为什么以下C++代码中存在内存泄漏?
- OpenCV 我应该使用智能指针来防止内存泄漏吗?
- 我是否生成线程并导致内存泄漏?
- 多线程程序中出现意外的内存泄漏
- 为什么此函数会导致内存泄漏?
- 在 C++ 库中使用cythonized python时内存泄漏
- 需要帮助查找内存泄漏
- 瓦尔格林德的内存泄漏使用新的
- 无法找出我的代码中的内存泄漏
- C++ 结构内部的unordered_map会导致内存泄漏问题吗?
- 可视化 使用 VS Code 查找C++应用程序中的内存泄漏
- Shared_ptr双链接列表内存泄漏
- C++ 在类中使用常量引用文本时 O2 内存泄漏