FIX: Memory Leak when Requerying with a CTime ParameterLast reviewed: September 18, 1997Article ID: Q115035 |
1.50
WINDOWS
kbprg kbfixlist kbbuglist
The information in this article applies to:
SYMPTOMSWhen running an MFC application that uses the database classes, the following message may appear in the Output Window of the debugger:
Detected memory leaks! Dumping objects -> {45}dbrfx.cpp(1331) : non-object block at $3FF74442, 16 bytes long Object dump complete.The message only occurs when you select a date/time field of a table, use RFX_Date() to map a CTime variable to the field, and call Requery().
CAUSELine 1331 in DBRFX.CPP includes the following code:
// Allocate TIMESTAMP_STRUCT for SQLBindCol pFX->m_prs->m_pvFieldProxy[nField-1] = new TIMESTAMP_STRUCT;This line runs each time date/time fields are bound to CTime recordset variables using the RFX_Date() record field exchange function. When doing a Requery(), the fields of the result set must be rebound to the CRecordset's variables, and thus a Requery() causes the memory leak to occur. The line of code shown above assigns a new value to an element of a pointer array, leaving the previous allocation stranded in memory.
RESOLUTIONTo resolve the memory leak, override the virtual Requery() function of CRecordset and delete the elements of the m_pvFieldProxy array. The following code demonstrates what to do: BOOL CMyAppRecordSet::Requery() { // delete proxies for recordset fields if (m_pvFieldProxy != NULL) { for (UINT nField = 0; nField != m_nFields; nField++) delete m_pvFieldProxy[nField]; } return CRecordset::Requery();}
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 1.51.
|
Additional reference words: ODBC 1.50 2.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |