https://www.postgresql.org/docs/9.6/static/libpq.html
<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.
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.
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?
DFS <nospam@dfs.com> writes:
https://www.postgresql.org/docs/9.6/static/libpq.html
<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.
There seems to be some kind of fundamental misunderstanding about the
nature of 'a result set' here. Specifically,
PGresult *res;
is a C pointer to a PGresult (structure) and in order to avoid memory
leaks, the result this pointer points to has to be freed before the
pointer is overwritten aka reused.
There's no need to free the result if the pointer won't be reused, IOW,
if the application is going to end next, anyway.
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
On 5/15/2017 11:38 AM, Rainer Weikusat wrote:
DFS <nospam@dfs.com> writes:
https://www.postgresql.org/docs/9.6/static/libpq.html
<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.
There seems to be some kind of fundamental misunderstanding about the
nature of 'a result set' here. Specifically,
PGresult *res;
is a C pointer to a PGresult (structure) and in order to avoid memory
leaks, the result this pointer points to has to be freed before the
pointer is overwritten aka reused.
There's no need to free the result if the pointer won't be reused, IOW,
if the application is going to end next, anyway.
The question is, if I use a PGresult 10x during a program, should I
clear it between each use, or is one clear at the end OK?
On 5/15/2017 1:54 PM, Robert Klemme wrote:
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.
I don't get hung up on scripting vs programming, compiled vs
interpreted, etc.
'when [PGResult object] is no longer needed' sounds like it can be
cleared once, at the end of the script.
:
In VB it's not necessary but I always closed them before the next
usage.
Set rs = db.openrecordset("SELECT DATA;")
if rs.recordcount > 0 then
... do things
endif
rs.close
Set rs = db.openrecordset("SELECT DATA 2nd time;")
if rs.recordcount > 0 then
... do things
endif
rs.close
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 21:50:24 |
Calls: | 6,646 |
Calls today: | 1 |
Files: | 12,191 |
Messages: | 5,327,495 |