Re: Newbie : Garbage Collection of Sequences (Server Side)



 
Hello Mr Beazley,

On Tue, 6 Nov 2001, Mr C.A.Beazley wrote:
> I'm very new to CORBA and am using Orbit with the C mappings.

        Welcome :-)

> I'm trying to write a CORBA server which returns a large sequence of
> strings to the client.  I don't know before hand how large the
> sequence will be so I am using a unbounded sequence

        Sounds great.

> The problem I'm having is that once I've returned the sequence, I
> don't know how get the server to free up the memory allocated to the   
> sequence, which results in large memory leakage.

        This is done in the skel; or in the client code - it's worth just
reading the skel a minute - it adds a whole load to ones understanding ( I
think ).

> CORBA_sequence_CORBA_string *
> get_StringSequence(PortableServer_Servant servant,CORBA_Environment *ev)
> {
>  
>          int count;
>          CORBA_sequence_CORBA_string *sequence;
>  
>          sequence=CORBA_sequence_CORBA_string__alloc();
>          sequence->_buffer=CORBA_sequence_CORBA_string_allocbuf(1000);
>          sequence->_length=1000;
>
>          for(count=0;count<1000;++count){
>                sequence->_buffer[count] = CORBA_string_dup ("Hello 
World\n");
>          }
>          return sequence;

        Ok :-) and here is where we learn about the _release flag.
Supposing that you were _certain_ that the caller was out of process (
this is most likely true ). There is an optimization built into the   
sequence that allows you to specify that the ORB should _not_ deallocate
the contained memory; This is called the release flag. Unintuitively it is
set to FALSE by the __alloc method:

        ie. the sequence will not be released; this would be wonderful if
you were not dupping your strings into it and not allocating the buffer; 
ie. with _release = FALSE; you can use the CORBA_sequence_CORBA_string as
your master data model - and return it _without_ getting it freed by the 
skel - which can be nice.

        So in short the solution to your leak is to add:
  
        sequence->_release=TRUE;

        somewhere before the return; or if you're a spec lover, there is
something like CORBA_sequence_...._set_release (sequence, TRUE); somewhere
lurking I think.

        HTH,

                Michael.

-- 
 mmeeks@gnu.org  <><, Pseudo Engineer, itinerant idiot




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]