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



On Tuesday 06 November 2001  4:08 pm, you wrote:
>
> 	You get it for free :). Once the ORB has marshalled your
> sequence it will free it for you.
>
> 	There's a lovely table in section 1.21 of the C language
> mapping that lays out this kind of stuff.
>

O.K. That means that I have misunderstood something fundemental about writing 
a simple server, cos I'm getting a nasty memory leak. So at the risk of 
public ridicule  ;)   I'll show you my server code in full, so that when 
you've stopped laughing, someone can shred it to bits and explain to me where 
I have got the basics wrong:-



IDL file
---------------------------------------------

interface FOO{
		typedef sequence<string> stringlist;
		stringlist get_StringSequence();
 };
----------------------------------------------



server code
---------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <orb/orbit.h>
#include "emboss-corba.h"

FOO foo_client = CORBA_OBJECT_NIL;

CORBA_sequence_CORBA_string *
get_StringSequence(PortableServer_Servant servant,
			CORBA_Environment *ev);

PortableServer_ServantBase__epv base_epv = {
  NULL,
  NULL,
  NULL
};

POA_FOO__epv foo_epv = {NULL,get_StringSequence,};
POA_FOO__vepv poa_foo_vepv = {&base_epv,&foo_epv};
POA_FOO poa_foo_servant = {NULL,&poa_foo_vepv};


/************************************************************************
*********************MAIN PROGRAM LOOP***********************************
*************************************************************************/
int
main (int argc, char *argv[])
{
PortableServer_ObjectId objid = {0,sizeof("my_ApplicationsString"),
    				     "my_ApplicationsString"};
PortableServer_POA poa;
CORBA_Environment ev;
char *retval;
CORBA_ORB orb;
FILE * ofp;

signal(SIGINT, exit);
signal(SIGTERM, exit);

CORBA_exception_init(&ev);
orb = CORBA_ORB_init(&argc, argv, "orbit-local-orb", &ev);
POA_FOO__init(&poa_foo_servant, &ev);

poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references(orb, 
    								 "RootPOA", 
								  &ev);
PortableServer_POAManager_activate(
                        PortableServer_POA__get_the_POAManager(poa, &ev),&ev);
    
PortableServer_POA_activate_object_with_id(poa, &objid, &poa_foo_servant,     
                                                                         &ev);

foo_client = PortableServer_POA_servant_to_reference(poa, &poa_foo_servant,
    						       &ev);
							     
if (!foo_client) {
        printf("Cannot get objref\n");
        return 1;
}

retval = CORBA_ORB_object_to_string(orb, foo_client, &ev);

ofp = fopen("foo.ior","w");
fprintf(ofp,"%s", retval);
fclose(ofp);

CORBA_free(retval);

fprintf(stdout,"Written the IOR file of this server.\n");
fflush(stdout);
CORBA_ORB_run(orb, &ev);
return 0;
}


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){
	       printf("%d\t",count);
	       sequence->_buffer[count] = CORBA_string_dup ("Hello dere\n");
	       printf("%d\t",count);
	}
	return sequence;	
}




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