Search code examples
c++gsoap

How to gsoap release memory work in c++ mode?


i use gsoap for generating some class for my web service, in destruct of my class i havent see any free or delete statement, must i delete member of class manualy? -- Or gsoup destroy function has responsible for do that? this is one of my sample classess:

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() { }
};

and i see tutorial for keeping alive soap for faster call on webservice like this example

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;

now we dont call destroy function of soap, so i havent need to worry for deleting soap object?


Solution

  • I have used gsoap generated files as components of a .dll project where in the .dll entry section I used the following:

    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;
    }
    

    This approach results in no memory leaks for me. You could possible use an adaptation of something like this within your c++code, could you not?