Click to See Complete Forum and Search --> : Memory Problem with COleDataObject


David Campeau
March 31st, 1999, 01:55 PM
Hi,

I have a problem in my code. If I run the Task Manager when my program is running, I can see clearly that I have a

memory problem. When ever OnUpdate

EditPaste is executed the memory grow's by about 4Kb. I can make it grow to 5Mb in under a minute!

Thanks in advance

David Campeau

void CDLabView::OnUpdateEditPaste( CCmdUI* pCmdUI )

{//test if it's a valid clipboard format and valid data for the selection

COleDataObject* obj = new COleDataObject();

pCmdUI->Enable(TestClipboardIntern(obj));

delete obj;

}

bool CDLabView::TestClipboardIntern(COleDataObject* obj)

{

if( obj->AttachClipboard())

{

//DLAB_CF_PRIVATE_FIRST was register with

//DLAB_CF_PRIVATE_FIRST = ::RegisterClipboardFormat(_T("DLAB1"));

if( obj->IsDataAvailable( DLAB_CF_PRIVATE_FIRST ))

{// If this block is commented there is no more memory problem

HGLOBAL hmem = obj->GetGlobalData( DLAB_CF_PRIVATE_FIRST );

CMemFile sf(( BYTE* )::GlobalLock( hmem ), ::GlobalSize( hmem ));

CArchive ar( &sf, CArchive::load );

//test if data is valid

bool bResult = ValidateArchive(ar);

ar.Close();

::GlobalUnlock( hmem );

//::GlobalFree( hmem ); // never return NULL

return bResult;

}

}

return false;

}

Wes Rogers
March 31st, 1999, 02:55 PM
Try doing


::DeleteObject(hmem);


before (after?) you do the unlock.


This helps with other resources such as HANDLE's -- maybe it will help here.


Yours,

Wes