for(;;)
{
m = svr.accept();
if (m < 0)
{
soap_print_fault(&svr, stderr);
exit(-1);
}
fprintf(stderr, "Socket connection successful: slave socket = %d/n", m);
svr.serve();
//break;
} 測試發現有記憶體流失問題:壓力測試下看見記憶體一直在漲,但正常退出(通過在迴圈中加break使程式正常結束)時記憶體能夠釋放完全(VC環境中沒有檢測到記憶體流失);Debug與Release版本都是這樣。
GSoap官方網站上(http://www.cs.fsu.edu/~engelen/soap.html)有一段說明,不知道針對哪個版本:The gSOAP engine uses a memory management method to allocate and deallocate memory. The deallocation is performed with soap_destroy() followed by soap_end(). However, when you compile with -DDEBUG or -DSOAP_MEM_DEBUG then no memory is released until soap_done() is invoked. This ensures that the gSOAP engine can track all malloced data to verify leaks and double frees in debug mode. Use -DSOAP_DEBUG to use the normal debugging facilities without memory debugging. Note that some compilers have DEBUG enabled in the debug configuration, so this behavior should be expected unless you compile in release config. 於是在 svr.serve();後加入代碼:
soap_destroy(&svr);
soap_end(&svr); 問題解決——與說明不符的是,沒發現Debug版與Release版的區別。 也可以直接調用svr.run()避免這一堆處理。記憶體泄露出處:http://blog.csdn.net/netnote/archive/2008/11/25/3367741.aspx