Page 1 of 1

How to free memory occupied by C++ routine

Posted: Thu Jun 19, 2008 2:40 pm
by kirankota79
I am using a c++ routine in the parallel jobs and some tables are huge and this routine is applied on every row of the column. It returns char*. After running some jobs , the next jobs are just getting aborted. I am doing force compile 3 to 4 times and then only the job is running. I don't know if this is due the memory occupied by the routine.

In future i want to use all these jobs to be used in a sequence and i don't want to go into all these problem of aborting.

Any suggestions please?

Posted: Thu Jun 19, 2008 11:05 pm
by mahadev.v
Instead of speculating on the probable cause, posting the exact error message here will help. As far as i know you don't have to handle the memory in a C++ routine explicitly. DataStage does it for you.

Posted: Fri Jun 20, 2008 12:10 am
by ray.wurlod
Space allocated to variables local to the routine should be freed. Or you might be able to use static variables.

Posted: Fri Jun 20, 2008 2:24 am
by OddJob
The problem is that you never get the opportunity to free the memory that you have allocated for a returned string.

I have tried the following type of code:

static char * pszReturnString = 0 ;

\\ For a 256 char return type
if ( pszReturnString == 0 ) pszReturnString=new char[256] ;

\\ Code...

return pszReturnString ;


This method has been advised in other posts on this forum.

The static allows the return string to persist, but in theory will always leave the one allocation of pszReturnString. I suspect though this will get freed when the related process finishes.

Alternatively you could just use:

static char szReturnString[256] ;

This auto variable is possibly a bit more friendly to memory garbage collection.