You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@axis.apache.org by Aleksander Slominski <as...@cs.indiana.edu> on 2004/05/28 18:27:54 UTC

memory management and AXIS_DEFINED_ARRAY

hi,

how is it supposed to be used - if i return new allocated 
AXIS_DEFINED_ARRAY will it be automatically deallocated?!

for example is this valid way to do echo? i have seen it in 
InteropTestPortType.cpp so that should be fine though in this case i do 
not understand who is de-allocating memory as xsd__int_Array is passed 
as input and returned as output? shouldnt service clone the array or 
auto pointer be used?

xsd__int_Array Benchmark1PortType::echoInts(xsd__int_Array Value0)
{
    return Value0;
}

and what about returning new value?

xsd__int_Array Benchmark1PortType::sendInts(int length)
{
    xsd__int_Array arr;
    arr.m_Size = length;
    arr.m_Array = (int *) malloc(length * sizeof(int));
    // fill in array with values
    return arr;
}

will it be de-allocated? do i miss something (documentation, examples)?

thanks,

alek

-- 
The best way to predict the future is to invent it - Alan Kay


RE: memory management and AXIS_DEFINED_ARRAY

Posted by Susantha Kumara <su...@opensource.lk>.
Hi Alek,

> -----Original Message-----
> From: Aleksander Slominski [mailto:aslom@cs.indiana.edu]
> Sent: Saturday, May 29, 2004 5:30 AM
> To: Apache AXIS C Developers List
> Subject: Re: memory management and AXIS_DEFINED_ARRAY
> 
> followup: it seems that skeleton is just calling
> 
>     pIWSSZ->addOutputBasicArrayParam((Axis_Array*)(&ret),XSD_INT,
> "echoIntsReturn");
> 
> after looking it in source code it seems thta is acutally called isL
> 
> SoapSerializer::addOutputBasicArrayParam(const Axis_Array* pArray,
>                                              XSDTYPE nType,
>                                              const AxisChar* pName)
> 
> which as far as i can tell does not deallocate pArray?

After sending a response(at server side) or after sending request (at
client side the Serializer object used is pooled back to be re-used.
When a Serializer object gets pooled its init() is called. Inside this
function this de-allocation of the objects is started. Eventually the
SoapMethod object's destructor is called where all added (serialized)
structures are deleted/deallocated.

See,

SoapMethod::~SoapMethod()
Param::~Param ()
And
ArrayBean::~ArrayBean()

---
Susantha

> 
> is it memory leak for sendInts?
> 
> if i have 3 methods like this what is the right way to manage memory
(by
> caller)?
> 
>         xsd__int_Array echoInts(xsd__int_Array Value0);
>         int receiveInts(xsd__int_Array Value0);
>         xsd__int_Array sendInts(int Value0);
> 
> thanks,
> 
> alek
> 
> 
> int Benchmark1PortTypeWrapper::sendInts(void* pMsg)
> {
>     IMessageData* mc = (IMessageData*)pMsg;
>     int nStatus;
>     IWrapperSoapSerializer *pIWSSZ = NULL;
>     mc->getSoapSerializer(&pIWSSZ);
>     if (!pIWSSZ) return AXIS_FAIL;
>     IWrapperSoapDeSerializer *pIWSDZ = NULL;
>     mc->getSoapDeSerializer(&pIWSDZ);
>     if (!pIWSDZ) return AXIS_FAIL;
>     /* check whether we have got correct message */
>     if (AXIS_SUCCESS != pIWSDZ->checkMessageBody("sendInts",
> "http://www.extreme.indiana.edu/wsdl/Benchmark1.wsdl")) return
AXIS_FAIL;
>     pIWSSZ->createSoapMethod("sendIntsResponse",
> "http://www.extreme.indiana.edu/wsdl/Benchmark1.wsdl");
>     int v0 = pIWSDZ->getElementAsInt("size",0);
>     if (AXIS_SUCCESS != (nStatus = pIWSDZ->getStatus())) return
nStatus;
>     xsd__int_Array ret = pWs->sendInts(v0);
>     return
pIWSSZ->addOutputBasicArrayParam((Axis_Array*)(&ret),XSD_INT,
> "sendIntsReturn");
> }
> 
> 
> int SoapSerializer::addOutputBasicArrayParam(const Axis_Array* pArray,
>                                              XSDTYPE nType,
>                                              const AxisChar* pName)
> {
>     IArrayBean* pAb = makeArrayBean(nType, (void*)(pArray->m_Array));
>     pAb->SetDimension(pArray->m_Size);
>     Param* pParam = new Param();
>     if (RPC_ENCODED == m_nStyle)
>     {
>         pAb->SetItemName("item");
>         pParam->setName(pName);
>     }
>     else
>     {
>         pAb->SetItemName(pName);
>         pParam->setName("array");
>     }
>     pParam->m_Value.pIArray = pAb;
>     pParam->m_Type = XSD_ARRAY;
>     if(m_pSoapEnvelope && (m_pSoapEnvelope->m_pSoapBody) &&
>         (m_pSoapEnvelope->m_pSoapBody->m_pSoapMethod))
>     {
>         m_pSoapEnvelope->m_pSoapBody->m_pSoapMethod-
> >addOutputParam(pParam);
>     }
>     return AXIS_SUCCESS;
> }
> 
> 
> IArrayBean* SoapSerializer::makeArrayBean(XSDTYPE nType, void* pArray)
> {
>     ArrayBean* pAb = new ArrayBean();
>     pAb->m_type = nType;
>     pAb->m_value.sta = pArray;
>     return pAb;
> }
> Aleksander Slominski wrote:
> 
> > hi,
> >
> > how is it supposed to be used - if i return new allocated
> > AXIS_DEFINED_ARRAY will it be automatically deallocated?!
> >
> > for example is this valid way to do echo? i have seen it in
> > InteropTestPortType.cpp so that should be fine though in this case i
> > do not understand who is de-allocating memory as xsd__int_Array is
> > passed as input and returned as output? shouldnt service clone the
> > array or auto pointer be used?
> >
> > xsd__int_Array Benchmark1PortType::echoInts(xsd__int_Array Value0)
> > {
> >    return Value0;
> > }
> >
> > and what about returning new value?
> >
> > xsd__int_Array Benchmark1PortType::sendInts(int length)
> > {
> >    xsd__int_Array arr;
> >    arr.m_Size = length;
> >    arr.m_Array = (int *) malloc(length * sizeof(int));
> >    // fill in array with values
> >    return arr;
> > }
> >
> > will it be de-allocated? do i miss something (documentation,
examples)?
> >
> > thanks,
> >
> > alek
> >
> 
> 
> --
> The best way to predict the future is to invent it - Alan Kay



Re: memory management and AXIS_DEFINED_ARRAY

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
followup: it seems that skeleton is just calling

    pIWSSZ->addOutputBasicArrayParam((Axis_Array*)(&ret),XSD_INT, 
"echoIntsReturn");

after looking it in source code it seems thta is acutally called isL

SoapSerializer::addOutputBasicArrayParam(const Axis_Array* pArray,
                                             XSDTYPE nType,
                                             const AxisChar* pName)

which as far as i can tell does not deallocate pArray?

is it memory leak for sendInts?

if i have 3 methods like this what is the right way to manage memory (by 
caller)?

        xsd__int_Array echoInts(xsd__int_Array Value0);
        int receiveInts(xsd__int_Array Value0);
        xsd__int_Array sendInts(int Value0);

thanks,

alek


int Benchmark1PortTypeWrapper::sendInts(void* pMsg)
{
    IMessageData* mc = (IMessageData*)pMsg;
    int nStatus;
    IWrapperSoapSerializer *pIWSSZ = NULL;
    mc->getSoapSerializer(&pIWSSZ);
    if (!pIWSSZ) return AXIS_FAIL;
    IWrapperSoapDeSerializer *pIWSDZ = NULL;
    mc->getSoapDeSerializer(&pIWSDZ);
    if (!pIWSDZ) return AXIS_FAIL;
    /* check whether we have got correct message */
    if (AXIS_SUCCESS != pIWSDZ->checkMessageBody("sendInts", 
"http://www.extreme.indiana.edu/wsdl/Benchmark1.wsdl")) return AXIS_FAIL;
    pIWSSZ->createSoapMethod("sendIntsResponse", 
"http://www.extreme.indiana.edu/wsdl/Benchmark1.wsdl");
    int v0 = pIWSDZ->getElementAsInt("size",0);
    if (AXIS_SUCCESS != (nStatus = pIWSDZ->getStatus())) return nStatus;
    xsd__int_Array ret = pWs->sendInts(v0);
    return pIWSSZ->addOutputBasicArrayParam((Axis_Array*)(&ret),XSD_INT, 
"sendIntsReturn");
}


int SoapSerializer::addOutputBasicArrayParam(const Axis_Array* pArray,
                                             XSDTYPE nType,
                                             const AxisChar* pName)
{
    IArrayBean* pAb = makeArrayBean(nType, (void*)(pArray->m_Array));
    pAb->SetDimension(pArray->m_Size);
    Param* pParam = new Param();
    if (RPC_ENCODED == m_nStyle)
    {
        pAb->SetItemName("item");
        pParam->setName(pName);
    }
    else
    {
        pAb->SetItemName(pName);
        pParam->setName("array");       
    }
    pParam->m_Value.pIArray = pAb;
    pParam->m_Type = XSD_ARRAY;
    if(m_pSoapEnvelope && (m_pSoapEnvelope->m_pSoapBody) &&
        (m_pSoapEnvelope->m_pSoapBody->m_pSoapMethod))
    {
        m_pSoapEnvelope->m_pSoapBody->m_pSoapMethod->addOutputParam(pParam);
    }
    return AXIS_SUCCESS;
}


IArrayBean* SoapSerializer::makeArrayBean(XSDTYPE nType, void* pArray)
{
    ArrayBean* pAb = new ArrayBean();
    pAb->m_type = nType;
    pAb->m_value.sta = pArray;
    return pAb;
}
Aleksander Slominski wrote:

> hi,
>
> how is it supposed to be used - if i return new allocated 
> AXIS_DEFINED_ARRAY will it be automatically deallocated?!
>
> for example is this valid way to do echo? i have seen it in 
> InteropTestPortType.cpp so that should be fine though in this case i 
> do not understand who is de-allocating memory as xsd__int_Array is 
> passed as input and returned as output? shouldnt service clone the 
> array or auto pointer be used?
>
> xsd__int_Array Benchmark1PortType::echoInts(xsd__int_Array Value0)
> {
>    return Value0;
> }
>
> and what about returning new value?
>
> xsd__int_Array Benchmark1PortType::sendInts(int length)
> {
>    xsd__int_Array arr;
>    arr.m_Size = length;
>    arr.m_Array = (int *) malloc(length * sizeof(int));
>    // fill in array with values
>    return arr;
> }
>
> will it be de-allocated? do i miss something (documentation, examples)?
>
> thanks,
>
> alek
>


-- 
The best way to predict the future is to invent it - Alan Kay


Re: memory management and AXIS_DEFINED_ARRAY

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Susantha Kumara wrote:

>Hi Alek,
>
>
>  
>
hi,

>>-----Original Message-----
>>From: Aleksander Slominski [mailto:aslom@cs.indiana.edu]
>>Sent: Friday, May 28, 2004 10:28 PM
>>To: Apache AXIS C Developers List
>>Subject: memory management and AXIS_DEFINED_ARRAY
>>
>>
>>    
>>
>The policies now are,
>1. Any objects passed to skeletons by Axis (created either by Axis
>Engine or wrappers) are not memory managed by Axis. These are
>created/populated/passed to skeletons and it's the responsibility of the
>skeleton to keep it or delete it.
>
>2. Any objects returned by the skeletons will be deleted (deallocated)
>by Axis after they are serialized. So the skeletons should not return
>any objects if they need to keep across several method calls (any
>persistent data). 
>
>  
>
i read this and your other two emails and i still do not understand it 
at all.

correct me if I am wrong but AXIS_DEFINED_ARRAY is struct with int* 
pointer inside and i fail to see how it will be automatically deallocated?

>>xsd__int_Array Benchmark1PortType::echoInts(xsd__int_Array Value0)
>>{
>>    return Value0;
>>}
>>    
>>
>
>Here this is perfectly OK because the skeleton doesn't need to keep the
>passed array.
>
>  
>
so no memory leak?

>>and what about returning new value?
>>
>>xsd__int_Array Benchmark1PortType::sendInts(int length)
>>{
>>    xsd__int_Array arr;
>>    arr.m_Size = length;
>>    arr.m_Array = (int *) malloc(length * sizeof(int));
>>    // fill in array with values
>>    return arr;
>>}
>>    
>>
>
>This is OK. But memory inside arr will if be deallocated by Axis Engine
>after serialization.
>
>  
>
could you tell me what is the *right* way to implement this method so 
there is no memory leak?

>>will it be de-allocated? 
>>    
>>
>
>Yes
>  
>
i will be testing it.

thanks,

alek

-- 
The best way to predict the future is to invent it - Alan Kay


RE: memory management and AXIS_DEFINED_ARRAY

Posted by Susantha Kumara <su...@opensource.lk>.
Hi Alek,

What I have mentioned below are how the policies at server side. Let me
list both client side and server side memory management policies,

Server Side
-----------
The policies are,
1. Any objects passed to skeletons by Axis (created either by Axis
Engine or wrappers) are not memory managed by Axis. These are
created/populated/passed to skeletons and it's the responsibility of the
skeleton to keep it or delete it.

2. Any objects returned by the skeletons will be deleted (deallocated)
by Axis after they are serialized. So the skeletons should not return
any objects if they need to keep across several method calls (any
persistent data).


Client Side
-----------
The policies are,
1. None of the objects passed to stubs by Client application will be
deleted by Axis Engine or stub. Axis Engine just use them for
serialization. But any memory allocated within Axis to facilitate
serialization (function pointer tables etc) will be memory managed by
Axis. So its the responsibility of the
client application to keep or delete any objects it passed to stubs.

2. Its also the responsibility of the client application to delete any
objects returned by stubs (created either by AxisEngine or stubs)These
objects are not memory managed by Axis. Axis Engine takes care of
managing any memory allocated to facilitate de-serialization of returned
objects.
 

---
Susantha Kumara
Virtusa (pvt) Ltd.
Office : +94112714385
Mobile : +94777420453

> -----Original Message-----
> From: Susantha Kumara [mailto:susantha@opensource.lk]
> Sent: Tuesday, June 01, 2004 3:08 PM
> To: 'Apache AXIS C Developers List'
> Subject: RE: memory management and AXIS_DEFINED_ARRAY
> 
> Hi Alek,
> 
> 
> > -----Original Message-----
> > From: Aleksander Slominski [mailto:aslom@cs.indiana.edu]
> > Sent: Friday, May 28, 2004 10:28 PM
> > To: Apache AXIS C Developers List
> > Subject: memory management and AXIS_DEFINED_ARRAY
> >
> > hi,
> >
> > how is it supposed to be used - if i return new allocated
> > AXIS_DEFINED_ARRAY will it be automatically deallocated?!
> 
> These AXIS_DEFINED_ARRAY s are always passed by value. So Axis doesn't
> need to do any memory management with it. But any memory pointed to by
> its m_Array member will be de-allocated after serialization.
> 
> See ArrayBean::~ArrayBean()
> 
> >
> > for example is this valid way to do echo? i have seen it in
> > InteropTestPortType.cpp so that should be fine though in this case i
> do
> > not understand who is de-allocating memory as xsd__int_Array is
passed
> > as input and returned as output? shouldnt service clone the array or
> > auto pointer be used?
> 
> The policies now are,
> 1. Any objects passed to skeletons by Axis (created either by Axis
> Engine or wrappers) are not memory managed by Axis. These are
> created/populated/passed to skeletons and it's the responsibility of
the
> skeleton to keep it or delete it.
> 
> 2. Any objects returned by the skeletons will be deleted (deallocated)
> by Axis after they are serialized. So the skeletons should not return
> any objects if they need to keep across several method calls (any
> persistent data).
> 
> >
> > xsd__int_Array Benchmark1PortType::echoInts(xsd__int_Array Value0)
> > {
> >     return Value0;
> > }
> 
> Here this is perfectly OK because the skeleton doesn't need to keep
the
> passed array.
> 
> >
> > and what about returning new value?
> >
> > xsd__int_Array Benchmark1PortType::sendInts(int length)
> > {
> >     xsd__int_Array arr;
> >     arr.m_Size = length;
> >     arr.m_Array = (int *) malloc(length * sizeof(int));
> >     // fill in array with values
> >     return arr;
> > }
> 
> This is OK. But memory inside arr will if be deallocated by Axis
Engine
> after serialization.
> 
> >
> > will it be de-allocated?
> 
> Yes
> 
> > do i miss something (documentation, examples)?
> >
> > thanks,
> >
> > alek
> >
> > --
> > The best way to predict the future is to invent it - Alan Kay
> 



RE: memory management and AXIS_DEFINED_ARRAY

Posted by Susantha Kumara <su...@opensource.lk>.
Hi Alek,


> -----Original Message-----
> From: Aleksander Slominski [mailto:aslom@cs.indiana.edu]
> Sent: Friday, May 28, 2004 10:28 PM
> To: Apache AXIS C Developers List
> Subject: memory management and AXIS_DEFINED_ARRAY
> 
> hi,
> 
> how is it supposed to be used - if i return new allocated
> AXIS_DEFINED_ARRAY will it be automatically deallocated?!

These AXIS_DEFINED_ARRAY s are always passed by value. So Axis doesn't
need to do any memory management with it. But any memory pointed to by
its m_Array member will be de-allocated after serialization.

See ArrayBean::~ArrayBean()

> 
> for example is this valid way to do echo? i have seen it in
> InteropTestPortType.cpp so that should be fine though in this case i
do
> not understand who is de-allocating memory as xsd__int_Array is passed
> as input and returned as output? shouldnt service clone the array or
> auto pointer be used?

The policies now are,
1. Any objects passed to skeletons by Axis (created either by Axis
Engine or wrappers) are not memory managed by Axis. These are
created/populated/passed to skeletons and it's the responsibility of the
skeleton to keep it or delete it.

2. Any objects returned by the skeletons will be deleted (deallocated)
by Axis after they are serialized. So the skeletons should not return
any objects if they need to keep across several method calls (any
persistent data). 

> 
> xsd__int_Array Benchmark1PortType::echoInts(xsd__int_Array Value0)
> {
>     return Value0;
> }

Here this is perfectly OK because the skeleton doesn't need to keep the
passed array.

> 
> and what about returning new value?
> 
> xsd__int_Array Benchmark1PortType::sendInts(int length)
> {
>     xsd__int_Array arr;
>     arr.m_Size = length;
>     arr.m_Array = (int *) malloc(length * sizeof(int));
>     // fill in array with values
>     return arr;
> }

This is OK. But memory inside arr will if be deallocated by Axis Engine
after serialization.

> 
> will it be de-allocated? 

Yes

> do i miss something (documentation, examples)?
> 
> thanks,
> 
> alek
> 
> --
> The best way to predict the future is to invent it - Alan Kay