Problems freeing memory using "free" 
Author Message
 Problems freeing memory using "free"

Hi ,
    My question is:
    When is dynamically allotted memory using c(m)alloc freed after
     calling "free"?

    Using os_view() on a SGI, I am able to monitor the RAM available
     before a call to c(m)alloc and after a call to free(). The OS
     indicates that the dynamic memory has been allotted from the
     available RAM(a test problem) and but then does not release the
     allotted memory even after a call to free. After the test program
     is completed and the prompt is back, then the memory is indicated
     as available.

   The available RAM is critical for my app, but future malloc's
   will allot memory from the swap space which I do not want to access.

   Have I misunderstood some concepts here or is there a technique by
   which i can access the RAM after a "free".

  Girish Bhat



Wed, 07 Jun 1995 05:03:46 GMT  
 Problems freeing memory using "free"

Quote:
> When is dynamically allotted memory using c(m)alloc freed after
> calling "free"?

By the time free returns, the memory has been freed and must not be
accessed again.  Most implementations will permit the memory to
continue to exist for some indeterminate time after free() returns;
some will even leave the former contents undisturbed for a while.  You
cannot depend on either of these.

Quote:
> Using os_view() on a SGI, I am able to monitor the RAM available
> before a call to c(m)alloc and after a call to free().  The OS
> indicates that the dynamic memory has been allotted from the
> available RAM(a test problem) and but then does not release the
> allotted memory even after a call to free.

This makes it an OS question, and as such it really belongs in the
appropriate OS-specific group, comp.sys.sgi or some such.

Most UNIXish systems' implementations of malloc never return memory to
the OS; memory being free simply means that it is available for further
calls to malloc.  Whether another call to malloc will allocate some or
all of the same memory is implementation-dependent and cannot be
counted upon either way.

Quote:
> The available RAM is critical for my app, but future malloc's will
> allot memory from the swap space which I do not want to access.

I'm not sure what the problem is here.  If you allocated a block and
freed it, and future mallocs don't return it, the system will push
those pages to swap because you're not accessing them, thus letting you
keep something else in-core instead.  If future mallocs do return that
same memory, no problem.

                                        der Mouse




Sat, 10 Jun 1995 01:15:23 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Error "free"-ing "malloc"-ed memory

2. Free a "2D dynamically allocated array"

3. question on "free" operation

4. Installing the "free" Borland C++ 5.5

5. Pulic Domain "free" compilers

6. Other "free" databases other than Access

7. free() causes: "Debug Assertion Failed"

8. Flicker-free "sprite"

9. Problem using free! - free.txt [1/1]

10. Memory Leakage problem using malloc and free

11. can I know the amount of memory freed by call to free

12. how free realy frees memory ?

 

 
Powered by phpBB® Forum Software