X-Received: by 10.129.69.13 with SMTP id s13mr436397ywa.147.1494957479355; Tue, 16 May 2017 10:57:59 -0700 (PDT) Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!t26no1215067qtg.1!news-out.google.com!l19ni6376qtf.1!nntp.google.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!post02.iad.highwinds-media.com!fx12.iad.POSTED!not-for-mail From: DFS Subject: Re: Anyone here do anything with libpq? Newsgroups: comp.databases.postgresql References: X-Mozilla-News-Host: news://usnews.blocknews.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: Lines: 50 Message-ID: X-Complaints-To: abuse@blocknews.net NNTP-Posting-Date: Tue, 16 May 2017 17:57:59 UTC Organization: blocknews - www.blocknews.net Date: Tue, 16 May 2017 14:01:24 -0400 X-Received-Bytes: 2437 X-Received-Body-CRC: 395675474 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Original-Bytes: 2355 Xref: csiph.com comp.databases.postgresql:775 On 5/15/2017 1:54 PM, Robert Klemme wrote: > 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: >> >> >> 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. >> >> >> '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? at the end of the C program, then. I don't get hung up on scripting vs programming, compiled vs interpreted, etc. >> 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 Thanks