Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.postgresql > #773

Re: Anyone here do anything with libpq?

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.databases.postgresql
Subject Re: Anyone here do anything with libpq?
Date Mon, 15 May 2017 19:54:50 +0200
Lines 40
Message-ID <enu8bbF8h9kU1@mid.individual.net> (permalink)
References <P6jSA.83362$qj5.21666@fx39.iad>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net wCWwU0SrWLXC5PVH2KtXLAaJvZhRD7Wv50tAKSJ96DgSQUjZQ=
Cancel-Lock sha1:M46PnQAL/hy/Moq2m1aRAqa5HLw=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
In-Reply-To <P6jSA.83362$qj5.21666@fx39.iad>
Xref csiph.com comp.databases.postgresql:773

Show key headers only | View raw


On 15.05.2017 16:41, DFS wrote:
> https://www.postgresql.org/docs/9.6/static/libpq.html
>
> Specifically, I'm curious about when/how often to clear a result set:
>
> <quote>
> PQclear
> Frees the storage associated with a PGresult. Every command result
> should be freed via PQclear when it is no longer needed.
>
> void PQclear(PGresult *res);
>
> You can keep a PGresult object around for as long as you need it; it
> does not go away when you issue a new command, nor even if you close the
> connection. To get rid of it, you must call PQclear. Failure to do this
> will result in memory leaks in your application.
> </quote>
>
> 'when it is no longer needed' sounds like it can be cleared once, at the
> end of the script.

What do you mean by "script"?  Aren't we talking about C or C++ here?

> If you have experience with this, did you feel like it was OK to clear
> it once at the end of the program, or every time before you used result
> object?

My advice is to clear it as soon as you do not need it any more.  This 
might be less important for a short running program but if you are 
writing some form of reusable code or a long running application then it 
is clearly advisable to rid of the data as soon as it is processed.  No 
point in holding on to memory longer than it is needed.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.databases.postgresql | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Anyone here do anything with libpq? DFS <nospam@dfs.com> - 2017-05-15 10:41 -0400
  Re: Anyone here do anything with libpq? Rainer Weikusat <rweikusat@talktalk.net> - 2017-05-15 16:38 +0100
    Re: Anyone here do anything with libpq? DFS <nospam@dfs.com> - 2017-05-16 10:45 -0400
      Re: Anyone here do anything with libpq? Rainer Weikusat <rweikusat@talktalk.net> - 2017-05-16 20:52 +0100
  Re: Anyone here do anything with libpq? Robert Klemme <shortcutter@googlemail.com> - 2017-05-15 19:54 +0200
    Re: Anyone here do anything with libpq? DFS <nospam@dfs.com> - 2017-05-16 14:01 -0400
      Re: Anyone here do anything with libpq? Robert Klemme <shortcutter@googlemail.com> - 2017-05-16 23:04 +0200
      Re: Anyone here do anything with libpq? George Neuner <gneuner2@comcast.net> - 2017-05-17 08:40 -0400

csiph-web