简体   繁体   English

gSOAP C ++客户端内存泄漏

[英]gSOAP C++ client memory leak

I have read the gSOAP docs and seen mentions of the fact that one should call soap_destroy(soap) and soap_end(soap) etc., however they are always examples with a single invocation on the service object. 我已经阅读了gSOAP文档,并看到有人提到应该调用soap_destroy(soap)和soap_end(soap)等事实,但是它们始终是对服务对象进行一次调用的示例。 The service I am using returns about 40KB of text with each invocation. 我使用的服务每次调用都会返回大约40KB的文本。 My problem is that memory usage grows linearly by about the same size for every request. 我的问题是每个请求的内存使用量线性增长大约相同的大小。 I added soap_destroy(service->soap) within getWords to no avail. 我在getWords中添加了soap_destroy(service-> soap)无济于事。 Can anyone indicate what cleanup code is missing from this code snippet? 谁能指出该代码段中缺少哪些清除代码? The requesting program should be running for days on end, so per request cleanup is what I am worried about rather than at shutdown. 请求程序应该连续运行几天,所以我担心的是每次请求清理而不是关闭。

I have posted below an analagous example (sans error checking) based on http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=43 , (it returns chunks of text right?). 我在下面发布了一个基于http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=43的类似示例(无错误检查)(它返回大块的文本吗?)。 Any help is greatly appreciated! 任何帮助是极大的赞赏!

#include "soapBibleWebserviceSoapProxy.h"
#include "BibleWebserviceSoap.nsmap"
#include <iostream>
extern "C" {
#include <unistd.h>
}

struct Service
{
    BibleWebserviceSoap service;

    std::string getWords(std::string &title, int chapter)
    {   
        _ns1__GetBibleWordsByBookTitleAndChapter req;
        _ns1__GetBibleWordsByBookTitleAndChapterResponse resp;
        req.BookTitle = &title;
        req.chapter   = 1;

        service.__ns2__GetBibleWordsByBookTitleAndChapter(&req, &resp);

        return *(resp.GetBibleWordsByBookTitleAndChapterResult);
    }
};

int main(int argc, char* argv[])
{
    Service s;
    std::string genesis("Genesis");
    for (int i=0; i<360; ++i)
    {   
        sleep(2);
        std::cout << s.getWords(genesis,1) << std::endl;
    }
    return 0;
}

Run your application under Valgrind (valgrind.org - usually installed by default on Linux) - it's the easiest way of tracking down memory leaks. 在Valgrind(valgrind.org-通常在Linux上默认安装)下运行应用程序-这是跟踪内存泄漏的最简单方法。

Do 1,000+ calls and on shutdown you'll see the leak. 进行1,000次以上的通话,关机时您会看到泄漏。 If the leak is not shown on shutdown, then some list or map collects entries but only releases them on shutdown - in this case use Massif (part of Valgrind) - it is also a great tool. 如果在关闭时未显示泄漏,则某些列表或映射会收集条目,但仅在关闭时释放它们-在这种情况下,请使用Massif(Valgrind的一部分)-这也是一个很好的工具。

It's not a direct answer, but a stack trace of the allocation that eats memory usually helps a lot in pin-pointing a reason of a leak. 这不是直接的答案,但是占用内存的分配的堆栈跟踪通常可以在查明泄漏原因方面有很大帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM