WG: ESQL/C : Cursors statistics ?
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Is a CLOSE CURSOR satisfied to free all memory or must there a explicit FREE CURSOR ? i use the following sequence and it seems, there was a memory leak EXEC SQL ALLOCATE DESCRIPTOR :pCmdId WITH MAX MAXCOLUMNS; EXEC SQL PREPARE :pCmdId FROM :pSQLCmd; EXEC SQL DESCRIBE :pCmdId USING SQL DESCRIPTOR :pCmdId; if (SQLC < 0) { /* ERROR */ return(FALSE); } /* Speicherplatz fuer DESCRIPTOR ist allokiert worden -> merken um spaeter freizugeben */ pTclDBStmt->bAllocDesc = TRUE; if (SQLC == 0) /* Select with result-Set */ { EXEC SQL DECLARE :pCmdId CURSOR FOR :pCmdId; EXEC SQL OPEN :pCmdId; bOpenCursor=TRUE; } else { EXEC SQL EXECUTE :pCmdId; bOpenCursor=FALSE; } if (bOpemCursor) { EXEC SQL CLOSE :pCmdId; } EXEC SQL FREE :pCmdId; EXEC SQL DEALLOCATE DESCRIPTOR :pCmdId; Whats?s wrong ? Thanks Roland -----Ursprungliche Nachricht----- Von: Art S. Kagel [SMTP:kagel@bloomberg.net] Gesendet am: Dienstag, 6. Juli 1999 22:11 An: informix-list@iiug.org Betreff: Re: ESQL/C : Cursors statistics ? Stephane Revil-Baudard wrote: > > Hi, > > I've several questions about CURSORs in ESQL/C (informix 7.24) > > 1)- I'd like to know how many CURSORs can I > declare/open at the same time ? The release notes say the number of open cursors per user is port specific. I have programs with close to 1000 running up to 20 copies of each with no problems. > 2)- Same question with CURSORs declared WITH HOLD Adding the WITH HOLD option should make no difference. > 3)- Is there a command that would give the max of > this figure ? > 4)- Is there a command that would give the number > of opened CURSORs ? No way to determine except to keep track yourself. > In fact, I declare and open a CURSOR WITH HOLD, then, > if there is an error in my program (timeout on access > to a distant database) > 5)- Do the CURSOR stay open ? Cursor's stay open until closed either by an explicit CLOSE or FREE or because of an emplied CLOSE when COMMITTING or ROLLING BACK another cursor if not WITH HOLD. > 6)- In my program, there is no FREE CURSOR, do you think > it could be a problem ? Just bad form. Like malloc() without free(). > thanks for your help You're welcome. Art S. Kagel
Roland Grzyb wrote: > > Is a CLOSE CURSOR satisfied to free all memory or must there a > explicit FREE CURSOR ? > > i use the following sequence and it seems, there was a memory leak > > EXEC SQL ALLOCATE DESCRIPTOR :pCmdId WITH MAX MAXCOLUMNS; > EXEC SQL PREPARE :pCmdId FROM :pSQLCmd; > EXEC SQL DESCRIBE :pCmdId USING SQL DESCRIPTOR :pCmdId; > if (SQLC < 0) { /* ERROR */ > return(FALSE); > } > /* Speicherplatz fuer DESCRIPTOR ist allokiert worden -> merken um spaeter freizugeben */ > pTclDBStmt->bAllocDesc = TRUE; > > if (SQLC == 0) /* Select with result-Set */ > { > EXEC SQL DECLARE :pCmdId CURSOR FOR :pCmdId; > EXEC SQL OPEN :pCmdId; > bOpenCursor=TRUE; > } > else > { > EXEC SQL EXECUTE :pCmdId; > bOpenCursor=FALSE; > } > > if (bOpemCursor) { > EXEC SQL CLOSE :pCmdId; > } > > EXEC SQL FREE :pCmdId; > > EXEC SQL DEALLOCATE DESCRIPTOR :pCmdId; > > Whats?s wrong ? You have to free the cursor; closing it releases no memory. You also have to free the prepared statement. You also have to free the descriptor. 2 out of 3 leaves you with a memory leak. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v0.60 -- see http://www.perl.com/CPAN #include <disclaimer.h>