V
viza
Hi all,
Suppose I have a piece of malloc'd memory that I need for the lifetime
of my program. Is there any reason to free it, or is it guaranteed to
be returned to the system on program termination?
(Theoretical and in practice responses welcome - I am developing for
GNU/Linux, but portability information is also useful. TIA! )
My question is basically, is the any difference between the following
two programs:
program1.c:
int main( void ){
void *ptr= malloc( SOME_SIZE );
whatever_operations( ptr );
exit( EXIT_SUCCESS );
}
program2.c:
void *global;
void freeer( void ){
free( global );
}
int main( void ){
void *ptr= malloc( SOME_SIZE );
global= ptr;
atexit( freeer );
whatever_operations( ptr );
exit( EXIT_SUCCESS );
}
Suppose I have a piece of malloc'd memory that I need for the lifetime
of my program. Is there any reason to free it, or is it guaranteed to
be returned to the system on program termination?
(Theoretical and in practice responses welcome - I am developing for
GNU/Linux, but portability information is also useful. TIA! )
My question is basically, is the any difference between the following
two programs:
program1.c:
int main( void ){
void *ptr= malloc( SOME_SIZE );
whatever_operations( ptr );
exit( EXIT_SUCCESS );
}
program2.c:
void *global;
void freeer( void ){
free( global );
}
int main( void ){
void *ptr= malloc( SOME_SIZE );
global= ptr;
atexit( freeer );
whatever_operations( ptr );
exit( EXIT_SUCCESS );
}