[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: [LI] free...



Hi Arun,
	As has already been written, "free" frees the memory that has been
allocated to a pointer using the malloc etc function calls... Supposing U
have allocated some memory to a variable with malloc, now if U free it the
memory that was reserved for u'r ptr now returns to the system, now say
that U've allocated some memory to a pointer using malloc and then do a
ptr=NULL, the memory area is *NOT* returned to the system and the pointer
is also not pointing to it so the area is now *TOTALLY INACCESSIBLE*
unless there is another pointer, say ptr2 to which U've assigned ptr like
ptr2 = ptr, I'm not very sure, but I think these memory areas are called
garbage areas or the like. Another situation arises where U've done the
following:

	ptr = malloc...
	ptr2 = ptr ;
 	free(ptr) ;

	In this case ptr2 is pointing to an invalid memory area, but there
will not be any errors and ptr2 is known as a dangling pointer - it is
still possible to assign values etc to ptr2 and the appropriate changes
will be made to the memory address, but nothing is to stop the os from
reallocating the address in question to some other pointer on a call to
malloc - therefore it is *ABSOLUTELY ESSENTIAL* to FREE a malloc'ed
pointer after it has been used, or before reuse...

Hope this helped...Narain.


On Tue, 25 Jan 2000, Arun K Desai wrote:

> Hi all,
> What "free" does???
> Suppose i am having a pointer say *ptr.
> If say free(ptr) what it does???
> If say  ptr=NULL what it does???
> Is it both are same????
> 
>                      Regards,
>                        Arun.


--------------------------------------------------------------------
The Linux India Mailing List Archives are now available.  Please search
the archive at http://lists.linux-india.org/ before posting your question
to avoid repetition and save bandwidth.