Click here to Skip to main content
16,011,784 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Spaces Pin
prasad_som6-Sep-05 4:58
prasad_som6-Sep-05 4:58 
GeneralRe: Spaces Pin
LCI6-Sep-05 5:00
LCI6-Sep-05 5:00 
General[Message Deleted] Pin
toxcct6-Sep-05 5:02
toxcct6-Sep-05 5:02 
AnswerRe: Xcopy command and spaces Pin
toxcct6-Sep-05 4:57
toxcct6-Sep-05 4:57 
GeneralRe: Xcopy command and spaces Pin
LCI6-Sep-05 5:04
LCI6-Sep-05 5:04 
GeneralRe: Xcopy command and spaces Pin
toxcct6-Sep-05 5:06
toxcct6-Sep-05 5:06 
AnswerRe: Xcopy command and spaces Pin
David Crow6-Sep-05 6:08
David Crow6-Sep-05 6:08 
Questionmemory leak - a basic misunderstanding Pin
IlanTal6-Sep-05 3:39
IlanTal6-Sep-05 3:39 
Could someone clear up a possible memory leak for me? In using ADO.NET in MFC Projects it is written:

#pragma push_macro("new")
#undef new

try
{
m_OleDbConnection = new OleDbConnection(
S"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\test.mdb"
);
m_OleDbConnection->Open(); // Open up the connection
m_OleDb = new OleDbCommand(S"select * from Persons", m_OleDbConnection);
m_Reader = m_OleDb->ExecuteReader();

int count = 0;

while (m_Reader->Read())
{
AddToList(count,m_Reader->get_Item("First Name")->ToString(),
m_Reader->get_Item("Last Name")->ToString(),
m_Reader->get_Item("Phone Number")->ToString()
);
count++;
}
}
catch(Exception *e)
{
AfxMessageBox(CString(e->ToString()));
}
__finally
{
m_Reader->Close();
m_OleDbConnection->Close();
}

#pragma pop_macro("new")

What is bothering me is there is a new with no delete. The most surprising one is m_OleDb which doesn’t even have a close, let alone a delete. I tried adding a close as well as a delete and neither was accepted by the compiler.

I open and close the database hundreds of times, so I wanted to consider leaving it open and then I started to think about the memory leak problem.

Can anyone give me a hint why a memory leak doesn’t seem to play here?

Thanks,
Ilan


AnswerRe: memory leak - a basic misunderstanding Pin
David Crow6-Sep-05 3:48
David Crow6-Sep-05 3:48 
GeneralRe: memory leak - a basic misunderstanding Pin
IlanTal6-Sep-05 3:55
IlanTal6-Sep-05 3:55 
GeneralRe: memory leak - a basic misunderstanding Pin
Tim Smith6-Sep-05 3:58
Tim Smith6-Sep-05 3:58 
GeneralRe: memory leak - a basic misunderstanding Pin
David Crow6-Sep-05 4:02
David Crow6-Sep-05 4:02 
Questionget local machine ethernet address Pin
rolati6-Sep-05 3:05
rolati6-Sep-05 3:05 
AnswerRe: get local machine ethernet address Pin
David Crow6-Sep-05 3:59
David Crow6-Sep-05 3:59 
GeneralRe: get local machine ethernet address Pin
Steve Mayfield6-Sep-05 19:59
Steve Mayfield6-Sep-05 19:59 
QuestionAES Implementation in C++ Decrypt Problem Pin
mustangnet6-Sep-05 3:02
mustangnet6-Sep-05 3:02 
Questionantialiasing with MFC Pin
T1TAN6-Sep-05 2:57
T1TAN6-Sep-05 2:57 
AnswerRe: antialiasing with MFC Pin
Neagoe Gabriel6-Sep-05 3:01
Neagoe Gabriel6-Sep-05 3:01 
GeneralRe: antialiasing with MFC Pin
T1TAN6-Sep-05 3:08
T1TAN6-Sep-05 3:08 
GeneralRe: antialiasing with MFC Pin
Neagoe Gabriel6-Sep-05 3:54
Neagoe Gabriel6-Sep-05 3:54 
GeneralRe: antialiasing with MFC Pin
T1TAN6-Sep-05 4:26
T1TAN6-Sep-05 4:26 
GeneralRe: antialiasing with MFC Pin
Anonymous6-Sep-05 5:49
Anonymous6-Sep-05 5:49 
Question_CrtIsValidHeapPointer(pUserData) ASSERTION Pin
dharani6-Sep-05 2:51
dharani6-Sep-05 2:51 
AnswerRe: _CrtIsValidHeapPointer(pUserData) ASSERTION Pin
Tim Smith6-Sep-05 3:45
Tim Smith6-Sep-05 3:45 
GeneralRe: _CrtIsValidHeapPointer(pUserData) ASSERTION Pin
dharani8-Sep-05 23:06
dharani8-Sep-05 23:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.