Re: problems with free()

leo mueller <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
hi vadiraj,

thanks for your answer! first i thought about that, too, but if i do a
simple ...

char *x = (char *) malloc(1024 * 1024 * 100);
memset(x, 0, 1024 * 1024 * 100);
free(x);

... and put some sleeps in between (& before return)... i can see (->
htop) that
the % of mem is decreasing during runtime.... hmm...

2009/4/28 Vadiraj <[email protected]>:
>
> On Tue, Apr 28, 2009 at 2:50 PM, leo mueller <[email protected]>
> wrote:
>>
>> hi all,
>>
>> i got a little problem with free() ... i am allocating mem for a
>> special struct and putting it afterwards
>> into a linked list. allocating works fine, but freeing not. i'm
>> tracking the program with htop. after
>> allocating, the percentage of mem usage stays constant ...
>>
>> the test-file is attached.
>>
>> any help is appreciated. big thanks :)
>
> free() will put the chunk into the free pool of the process and not free
> away from the
> process. When you do a malloc again it would first try from the free pool,
> if it finds
> the size requested in the free pool it will give you the same.
> Hence you would not see any change.
>
> You can check that by, freeing an address and then requesting the same size.
> You will see that address freed and address allocated will be same in most
> of
> the case.
>
> Hope this helps.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.