Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to write content of file in to a structure Pin
Cedric Moonen29-Jun-06 2:58
Cedric Moonen29-Jun-06 2:58 
GeneralRe: How to write content of file in to a structure Pin
birajendu29-Jun-06 3:46
birajendu29-Jun-06 3:46 
GeneralRe: How to write content of file in to a structure Pin
Cedric Moonen29-Jun-06 3:48
Cedric Moonen29-Jun-06 3:48 
GeneralRe: How to write content of file in to a structure Pin
birajendu29-Jun-06 3:55
birajendu29-Jun-06 3:55 
GeneralRe: How to write content of file in to a structure Pin
Cedric Moonen29-Jun-06 3:58
Cedric Moonen29-Jun-06 3:58 
GeneralRe: Pin
birajendu29-Jun-06 3:56
birajendu29-Jun-06 3:56 
AnswerRe: How to write content of file in to a structure Pin
Jun Du29-Jun-06 3:49
Jun Du29-Jun-06 3:49 
QuestionMemory leak [modified] Pin
pierre_ribery29-Jun-06 2:48
pierre_ribery29-Jun-06 2:48 
Hi Gurus!

I have an MFC activeX component which creates a memory leak in the application that uses it. The leak is when exiting program. I have created a small example to show you what happens.

In my activeX component I have this method;

Code:

LONG CThursdayActiveXCtrl::getSomething(VARIANT* pVar)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

// A safe array of float
CComSafeArray <float> saVars;


// Insert elements into the CComSafeArray
saVars.Add(1); //THIS LINE GIVES A LEAK!!! SEE BELOW
saVars.Add(32);
saVars.Add(43);

// A CComVariant to return to the client
CComVariant varReturn (saVars.Detach ());
varReturn.vt=VT_R4;

return varReturn.Detach (pVar);
}




I have added my activex control to a dialog based MFC application. I have a button, when that button is pushed this method is called:

Code:

void Ctest1Dlg::OnBnClickedButton1()
{
CComVariant varArray;

// Get the array from the server
test.getSomething(&varArray);

// Attach the safe array
CComSafeArray <float> saFromVariant;
saFromVariant.Attach (varArray.parray);

a=saFromVariant.GetAt(0);
b=saFromVariant.GetAt(1);
c=saFromVariant.GetAt(2);
UpdateData(false);
}


My debugging tool, which is DevPartner gives me the following memory leak:

Memory Leak Exiting Program: Address 0x024101A0 (40) allocated by SafeArrayCreate.

The call stack gives me this lines of code causing the leak;
atlsafe.h 534
atlsafe.h 521
atlsafe.h 373
getSomething 195 (which is the line I have marked in the code above).


Can anyone help me out here? This leak is 40 bytes big, and that will become quite a large amount when the method in my real control is invoked approx. 5 times a second!!

Thanks for any help!

-- modified at 14:12 Thursday 29th June, 2006
AnswerRe: Memory leak Pin
Zac Howland29-Jun-06 3:56
Zac Howland29-Jun-06 3:56 
GeneralRe: Memory leak Pin
pierre_ribery29-Jun-06 4:07
pierre_ribery29-Jun-06 4:07 
GeneralRe: Memory leak Pin
Zac Howland29-Jun-06 5:11
Zac Howland29-Jun-06 5:11 
AnswerRe: Memory leak [modified] Pin
Viorel.29-Jun-06 4:10
Viorel.29-Jun-06 4:10 
GeneralRe: Memory leak Pin
pierre_ribery29-Jun-06 20:47
pierre_ribery29-Jun-06 20:47 
QuestionTimer in user class Pin
jsumm29-Jun-06 2:42
jsumm29-Jun-06 2:42 
AnswerRe: Timer in user class Pin
Cedric Moonen29-Jun-06 3:09
Cedric Moonen29-Jun-06 3:09 
GeneralRe: Timer in user class Pin
jsumm29-Jun-06 4:22
jsumm29-Jun-06 4:22 
GeneralRe: Timer in user class Pin
Cedric Moonen29-Jun-06 4:31
Cedric Moonen29-Jun-06 4:31 
GeneralRe: Timer in user class Pin
jsumm29-Jun-06 5:15
jsumm29-Jun-06 5:15 
GeneralRe: Timer in user class Pin
Cedric Moonen29-Jun-06 5:30
Cedric Moonen29-Jun-06 5:30 
QuestionOPC Server Pin
Sanjay6429-Jun-06 2:31
Sanjay6429-Jun-06 2:31 
Questionproblem with mouse_event() Pin
V_shr29-Jun-06 2:20
V_shr29-Jun-06 2:20 
AnswerRe: problem with mouse_event() Pin
Justin Tay29-Jun-06 2:47
Justin Tay29-Jun-06 2:47 
GeneralRe: problem with mouse_event() Pin
V_shr29-Jun-06 3:33
V_shr29-Jun-06 3:33 
GeneralRe: problem with mouse_event() Pin
Justin Tay29-Jun-06 3:41
Justin Tay29-Jun-06 3:41 
GeneralRe: problem with mouse_event() Pin
V_shr29-Jun-06 3:50
V_shr29-Jun-06 3:50 

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.