slang-users mailing list

[2001 Date Index] [2001 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: S-Lang Exit procedure


Francois Guimond <fguimond@xxxxxxxxxx> wrote:
>Is there any way to free all the stuff allocated by :
> 
>SLang_init_all (); 
>SLadd_intrin_fun_table (My_Intrinsics, NULL); 
>SLadd_intrinsic_variable ("I_Variable", &I, SLANG_INT_TYPE, 0));

Not until version 2.0.

>I want to exit my program without memory leak...
>In the documentation and slang.h, I only found :
> 
>SLang_exit_error (char *, ...);
>
>But I still have tons of leak.

As far as I know, there are no real memory leaks in the slang library.
For example, here is a program with a real memory leak:

void leak ()
{
   char *ptr = malloc (256);
}

int main ()
{
    leak ();
    leak ();
}

That is, each time leak is called, 256 bytes are lost during program
execution.   However, using

char *ptr;
void leak ()
{
   if (ptr != NULL) free (ptr);
   ptr = malloc (256);
}

does produce a leak since one call call 'leak' many times without losing
memory.

But note one thing: After main returns, the global variable 'ptr' will
point to an allocated block of 256 bytes, which some over zealous
memory checkers will flag as a leak.  However, as illustrated above,
this is not a true leak.  Hence, programs such as purify, which is my
favorite checker, do not report such false leaks.  Of course, this is
a false leak as long as your OS deallocates memory allocated by the
process after the process exits.

--John


[2001 date index] [2001 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]