Does free( ) immediatly free the memory?
I have been using Valgrind on some C code and have gotten all memory leaks patched (except one here that has not been answered yet that still plaques me,HINT HINT please respond here if you have an idea!). I am running this on both Red Hat AS and Solaris 8. When running on Red Hat, the memory usage will slowly climb until the system crashes. On Solaris however, the memory will slowly climb, and then quickly return back to the original amount. I know that there used to be a malloc library on Solaris that when linked to, immediately free'd the memory when free( ) was called, else the "standard" version free'd the memory, but kept it in a reserve until a later time. Is this the case with Linux/Red Hat? Are there any commands to force free( ) to allow access to all the memory? The application in question is a background daemon process that processes files and does not shut down.
Thanks oh so much! Rayven |
First, the command free does not free anything. It just tells what memory is being used and what is not being used. From man free:
Code:
free displays the total amount of free and used physical and swap memory in http://gentoo-wiki.com/FAQ_Linux_Memory_Management That one has some Gentoo specifics but a lot of it is the same for Linux in general. This is a distro independant I think: http://www.linuxhq.com/guides/TLK/mm/memory.html Linux handles memory a lot different than windoze. Hope that helps. :D :D :D :D :D |
Quote:
|
No apologies needed. I was going by your post count and thought you were new to Linux in general but at the same time your post made it sound like you were familiar with Linux. I wasn't really sure so I tried to include information that would then get additional info if you still had questions. Most people coming from windoze systems freak out when it says most all of the ram is in use. They don't realize that Linux caches as much as possible. That was the reason for the windoze comment.
Maybe someone with knowledge of 'C' routines will shed more light. :D :D :D :D :D |
Quote:
|
free() call usually frees the memory just when it's called. System crash shouldn't happen in such case, if free is really called. Caches may be in use in your case (there are many different factors here), but should not lead to a crash, definitelly.
I wouldn't blame Linux at this point. You may have a subtle bug in your code that causes such behaviour (valgrind is good, but it can't find all the possible problems). Make a small test. Run the program with memory limit per process (using ulimit). Check if it reaches the limit and/or if it crashes after that. |
Actually freed memory is returned to the system only under certain conditions.
Traditional malloc libraries only alloc on the heap and never use brk to lower it. With them, allocated memory is never returned to the O/S. This is documented in the Solaris free manual page. On linux, glibc malloc use either the heap or mmap, depending on the size of the requested size. Memory is guaranteed to be free only with mmap. With heap allocation, this can happen only if there is no allocated areas live between the just freed one and the heap limit. Finally, don't forget all this is about virtual memory. Physical usage is mostly unrelated. |
Sorry to go slightly offtopic, but
Quote:
Is that all within the context of a single process? Multiple processes? It seems to me that your statement needs some clarification. |
You got this wrong, sorry for having been not clear enough.
Malloc and free span is limited to a process, so allocations make by A have no relationship with allocations make by B, C or D. They are using unrelated virtual memory addresses (what my last sentence was telling) My statement is valid if a single process is doing these 4 allocations though. |
Quote:
Quote:
|
Quote:
|
Quote:
Quote:
As Hko stated, there is no interest building your own allocation library under Gnu/Linux, as malloc does already it for you. |
Quote:
Quick valgrind question, pertaining to this topic: if I am receiving multiple messages about "Invalid Read Size of 8" and "Use of Unitialized Value of size 8", would they make the memory leaks? I thought that these two warnings did not have much to do with memory leaks but just warnings of possible "bad" things. http://valgrind.org/docs/manual/mc-m...nual.errormsgs, maybe I read the documentation incorrectly. Thanks again! |
Quote:
I'm asking what values are you looking at in the vmstat and the top output. Quote:
Quote:
|
Quote:
|
All times are GMT -5. The time now is 12:54 AM. |