如何在c++模式下gsoap释放内存
How to gsoap release memory work in c++ mode?
我使用gsoap为我的web服务生成一些类,在类的析构函数中,我没有看到任何free或delete语句,我必须手动删除类的成员吗?--或者gsoup销毁功能有责任这么做?这是我的一个示例类:
class SOAP_CMAC ns2__FirstOfflineReserve
{
public:
short *consumed; /* optional element of type xsd:short */
class ns2__FirstOfflineFood *food; /* optional element of type ns2:FirstOfflineFood */
class ns2__FirstOfflineFoodType *foodType; /* optional element of type ns2:FirstOfflineFoodType */
int *id; /* optional element of type xsd:int */
class ns2__FirstOfflineMeal *meal; /* optional element of type ns2:FirstOfflineMeal */
short *remainCount; /* optional element of type xsd:short */
short *selectedCount; /* optional element of type xsd:short */
std::string *serialCard; /* optional element of type xsd:string */
std::string *username; /* optional element of type xsd:string */
struct soap *soap; /* transient */
public:
virtual int soap_type() const { return 36; } /* = unique id SOAP_TYPE_ns2__FirstOfflineReserve */
virtual void soap_default(struct soap*);
virtual void soap_serialize(struct soap*) const;
virtual int soap_put(struct soap*, const char*, const char*) const;
virtual int soap_out(struct soap*, const char*, int, const char*) const;
virtual void *soap_get(struct soap*, const char*, const char*);
virtual void *soap_in(struct soap*, const char*, const char*);
ns2__FirstOfflineReserve() { ns2__FirstOfflineReserve::soap_default(NULL); }
virtual ~ns2__FirstOfflineReserve() { }
};
我看到了保持soap活力的教程,以便更快地调用Web服务,比如这个例子
calcProxy calc(SOAP_IO_KEEPALIVE); // keep-alive improves connection performance
double sum = 0.0;
double val[] = 5.0, 3.5, 7.1, 1.2 ;
for (int i = 0; i < 4; i++)
if (calc.add(sum, val[i], sum))
return calc.error;
std::cout << "Sum = " << sum << std::endl;
return 0;
现在我们不调用soap的destroy函数,所以我不需要担心删除soap对象?
我使用了gsoap生成的文件作为.dll项目的组件,在.dll条目部分我使用了以下内容:
int __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
/* create a soap environment (provides soap services) */
soap = soap_new();
break;
case DLL_PROCESS_DETACH:
/* terminate soap services */
soap_end(soap); //discontinue soap services
soap_free(soap); //free soap resources
break;
}
/* Return 1 to indicate successful initialization */
return 1;
}
这种方法对我来说没有内存泄漏。你可以在你的c++代码中使用类似的东西的改编,不是吗?
相关文章:
- 释放错误后堆使用
- G锁定铸造到基础上会释放模拟行为
- 在将变量声明为引用时,堆在释放后使用
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 使用GSoap实现ONVIF
- 正在理解智能指针,但出现错误:未分配正在释放的指针
- 使用 mod_gsoap 部署服务时,如何在 Gsoap 中更改 soap 上下文的模式?
- C++双重释放或损坏(out)
- 如何在c++中释放内存
- 使用全局声明的向量时,C++双重释放错误/损坏
- gSoap在从.wsdl创建.h期间出现错误
- 为什么这个 std::queue/指向结构的指针列表直到 List.Size() == 0 才释放内存?
- 为什么瓦尔格林德在不释放恶意内存后没有报告任何问题?
- 调用析构函数以释放动态分配的内存
- 在函数范围内在堆栈上分配的数组在离开函数时是否总是被释放?
- COM :是否可以查看是否存在对我的某个 COM 对象的进程外引用?我可以释放它吗?
- 如何在向量中释放指针?
- std::unordered_map析构函数不释放内存?
- 在C++中释放内存期间,迭代器与指针有何不同
- 如何在c++模式下gsoap释放内存