Application Virtual address space memory allocation - memory does not get free
I am using malloc and frees a lot in my program. It shows its allocated but when i remove it doesnt show as the memory is removed(I am using the top command to view VIRT memory usage). If this continously grows what would happen to my program (Will it go out of memory?)
You only need to be alarmed if you keep seeing memory usage GROW even after you know you've freed it.
It would be extremely inefficient to shrink and grow program size every time you malloc and free new data. As an optimization, "free()" only marks de-allocated memory as "available", and "malloc()" tries to re-use previously allocated memory whenever possible.
So no, there's probably nothing to worry about - the system is doing exactly what it's supposed to :)
I have checked my program for memory leaks and found None(Valgrind,purify). I have growing memory problem each time i execute some tasks of the program memory grows but the growth degrades after number of times
times i execute the same tasks
1st time VIRT memory - 1023MB
2nd time - 1123MB
3rd Time - 1190MB
4th Time - 1210MB
5th Time - 1220MB
So the memeory growth degrades as we go along. If there is no problem with memory leaks, can we make sure that the freed memory will be available for the process regardless of this growth shown. THere is a virtual addess space cutover at 3GB in 32bit RH4 i guess.
Does anyone knw what will happen if we malloc and free small chunks of memory(3KB) many times. Does the virtual address space do a memory fragementaion? Please help
Did you start two threads for this same question? Or did you change your user ID and start three threads for the one question:
Having part of the details we need to give a specific answer in each of three threads makes it much more difficult to provide an answer.
But that estimate is extrapolating a lot from your unclear statements.
When malloc allocates a chunk, it might not have a free one of exactly the right size nor have a big contiguous free area, so it might split a slightly larger chunk into the chunk needed and a small fragment that won't get used. If you later need the size that it split, it might no longer be available, causing malloc to split a larger chunk again. Soon malloc would need to get more from the OS even though the total of all allocations might not be changing much.
So in that rolling replace mode (unlike the deleting it all at the end of each task and reallocating for the next task) the average amount wasted for allocations might gradually go up as the rolling replace varies the chunk sizes.
But the fragments aren't lost forever. They come back when you free the adjacent chunks. So as you continue such a rolling replace, the amount that the average freed size exceeds the actual use should soon catch up with the amount the average allocation cost exceeds the actual use.
All of that assumes a rolling replace design with random small size variations. That is an even wilder extrapolation from the little info you have provided.
Sorry for the delay in replying this thread. Do you know a tool to check actual memory usage for a process. Why i am asking this is I have a process it actually allocates small chuncks of data and release everything at the end. However the top command does not seem to show that. I used purify and valigrind to check for memory leaks too but didnt find any leaks on my program. I am currently looking at VIRT from the top, it actually shows an increase all the time. How am i suppose to know that the freed memory is aavailable to process and they can be reused since the there is not +/- shown in the VIRT column in top,
|All times are GMT -5. The time now is 05:23 AM.|