CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 1999
    Posts
    3

    Memory Problem with COleDataObject



    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&quot);

    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;

    }

  2. #2
    Join Date
    Apr 1999
    Posts
    53

    Re: Memory Problem with COleDataObject



    Try doing


    :eleteObject(hmem);


    before (after?) you do the unlock.


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


    Yours,

    Wes



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured