free


free

Releases allocated memory

 #include <stdlib.h> void free ( void *ptr  ); 

After you have finished using a memory block that you allocated by calling malloc( ), calloc( ) or realloc( ), the free( ) function releases it to the system for recycling. The pointer argument must be the exact address furnished by the allocating function, otherwise the behavior is undefined. If the argument is a null pointer, free( ) does nothing. In any case, free( ) has no return value.

Example

 char *ptr; /* Obtain a block of 4096 bytes ... */ ptr = calloc(4096, sizeof(char)); if ( ptr == NULL )   fprintf( stderr, "Insufficient memory.\n" ), abort( ); else { /* ... use the memory block ... */   strncpy( ptr, "Imagine this is a long string.\n", 4095 );   fputs( stdout, ptr ); /* ... and release it. */   free( ptr ); } 

See Also

malloc( ), calloc( ), realloc( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net