Обсуждение: Memory Usage and libpq

Поиск
Список
Период
Сортировка

Memory Usage and libpq

От
Keary Suska
Дата:
I am investigating a memory usage issue and I noticed something with libpq.
It appears that libpq doesn't actually free memory allocated to store
results, even after PQclear() is called. In a debug program I can inspect
the buffer so I know it exists. I haven't verified whether the buffer is
resized with subsequent calls, but when dealing with large result sets it
creates a significant memory overhead.

Am I on to something here or do I need to keep looking? If so, is there any
way that I can force libpq to free or in some way drastically reduce this
biffer?

Thanks,

Keary Suska
(719) 473-6431
(719) 440-9952 (cell)



Re: Memory Usage and libpq

От
Terry Lee Tucker
Дата:
On Tuesday 04 April 2006 03:14 pm, Keary Suska saith:
> I am investigating a memory usage issue and I noticed something with libpq.
> It appears that libpq doesn't actually free memory allocated to store
> results, even after PQclear() is called. In a debug program I can inspect
> the buffer so I know it exists. I haven't verified whether the buffer is
> resized with subsequent calls, but when dealing with large result sets it
> creates a significant memory overhead.
>
> Am I on to something here or do I need to keep looking? If so, is there any
> way that I can force libpq to free or in some way drastically reduce this
> biffer?
>
> Thanks,
>
> Keary Suska
> (719) 473-6431
> (719) 440-9952 (cell)
>

Keary,

I may be wrong about this, but just because you can access the memory after 
the call to PQclear, doesn't mean that the memory wasn't freed; it just means 
it hasn't been reused yet. The address still exists and freeing the memory 
doesn't "clear" it out.


Re: Memory Usage and libpq

От
Keary Suska
Дата:
on 4/4/06 11:23 AM, terry@esc1.com purportedly said:

> 
> On Tuesday 04 April 2006 03:14 pm, Keary Suska saith:
>> I am investigating a memory usage issue and I noticed something with libpq.
>> It appears that libpq doesn't actually free memory allocated to store
>> results, even after PQclear() is called. In a debug program I can inspect
>> the buffer so I know it exists. I haven't verified whether the buffer is
>> resized with subsequent calls, but when dealing with large result sets it
>> creates a significant memory overhead.
>> 
>> Am I on to something here or do I need to keep looking? If so, is there any
>> way that I can force libpq to free or in some way drastically reduce this
>> biffer?
> 
> I may be wrong about this, but just because you can access the memory after
> the call to PQclear, doesn't mean that the memory wasn't freed; it just means
> it hasn't been reused yet. The address still exists and freeing the memory
> doesn't "clear" it out.

It almost goes without saying, but it does encourage me to question whether
my debug program is showing deallocated memory, or further, if for some
reason the system/runtime isn't giving the memory back to the kernel
(something I am pursuing elsewhere). I will run a test of my own and see if
my debug program is showing deallocated memory.

Thanks,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"



Re: Memory Usage and libpq

От
Tom Lane
Дата:
Keary Suska <hierophant@pcisys.net> writes:
> I am investigating a memory usage issue and I noticed something with libpq.
> It appears that libpq doesn't actually free memory allocated to store
> results, even after PQclear() is called. In a debug program I can inspect
> the buffer so I know it exists. I haven't verified whether the buffer is
> resized with subsequent calls, but when dealing with large result sets it
> creates a significant memory overhead.

This would depend entirely on how malloc/free are implemented on your
platform.  Some versions can release space back to the OS, some can't.
In some it depends on what else has been allocated.
        regards, tom lane