CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Managed C++ and C++/CLI
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Managed C++ and C++/CLI Discuss Managed C++ and .NET-specific questions related to C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old July 8th, 2005, 08:59 AM
    amgturk amgturk is offline
    Junior Member
     
    Join Date: Jul 2005
    Posts: 15
    amgturk is an unknown quantity at this point (<10)
    memory leaks

    hii
    I need help about memory leaks.
    In my project when my application finishes then memory leakage is detected.
    I could detect where memory leakages occured but the leakages correspond to codes taht app wizard makes.
    Can u help me.how can ı solve this ?

    When ı looked lines that leakages occured they're in

    IMPLEMENT_DYNCREATE(CrenkoView, CView)
    IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
    IMPLEMENT_DYNCREATE(CrenkoDoc, CDocument)

    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CrenkoDoc),
    RUNTIME_CLASS(CMainFrame), // main SDI frame
    RUNTIME_CLASS(CrenkoView)); // window


    Detected memory leaks!
    Dumping objects ->
    {2136} normal block at 0x003855B8, 25 bytes long.
    Data: < .| > 10 FF 2E 7C 08 00 00 00 08 00 00 00 01 00 00 00
    array_p.cpp(105) : {2130} normal block at 0x00387D98, 20 bytes long.
    Data: < lT8 > 00 00 00 00 6C 54 38 00 00 00 00 00 CD CD CD CD
    array_p.cpp(66) : {2129} normal block at 0x00387D58, 4 bytes long.
    Data: < > 00 00 00 00
    winfrm2.cpp(62) : {2128} client block at 0x00387C58, subtype c0, 192 bytes long.
    a CDockBar object at $00387C58, 192 bytes long
    array_p.cpp(66) : {2127} normal block at 0x00387C18, 4 bytes long.
    Data: < > 00 00 00 00
    winfrm2.cpp(62) : {2126} client block at 0x00387B18, subtype c0, 192 bytes long.
    a CDockBar object at $00387B18, 192 bytes long
    array_p.cpp(66) : {2125} normal block at 0x00387878, 4 bytes long.
    Data: < > 00 00 00 00
    winfrm2.cpp(62) : {2124} client block at 0x00387A18, subtype c0, 192 bytes long.
    a CDockBar object at $00387A18, 192 bytes long
    winfrm2.cpp(62) : {2122} client block at 0x00387918, subtype c0, 192 bytes long.
    a CDockBar object at $00387918, 192 bytes long
    bardock.cpp(739) : {2121} normal block at 0x00387788, 176 bytes long.
    Data: < y | > D4 79 14 7C CD CD CD CD CD CD CD CD CD CD CD CD
    {2120} normal block at 0x003878C0, 21 bytes long.
    Data: < .| > 10 FF 2E 7C 04 00 00 00 04 00 00 00 01 00 00 00
    {2119} normal block at 0x00385950, 20 bytes long.
    Data: < .| > 10 FF 2E 7C 03 00 00 00 03 00 00 00 01 00 00 00
    {2118} normal block at 0x003874D8, 20 bytes long.
    Data: < .| > 10 FF 2E 7C 03 00 00 00 03 00 00 00 01 00 00 00
    {2115} normal block at 0x003876F8, 80 bytes long.
    Data: < > 00 00 00 00 00 01 00 00 00 01 00 08 00 00 00 00
    plex.cpp(27) : {2112} normal block at 0x00387640, 124 bytes long.
    Data: < Pv8 lT8 > 00 00 00 00 50 76 38 00 00 00 00 00 6C 54 38 00
    plex.cpp(27) : {2111} normal block at 0x00387588, 124 bytes long.
    Data: < `X8 > 00 00 00 00 00 00 00 00 00 00 00 00 60 58 38 00
    e:\documents and settings\renko\desktop\örnek\renko\renkoview.cpp(63) : {84} client block at 0x00385860, subtype c0, 88 bytes long.
    a CrenkoView object at $00385860, 88 bytes long
    {80} normal block at 0x00385638, 22 bytes long.
    Data: < .| > 10 FF 2E 7C 05 00 00 00 05 00 00 00 01 00 00 00
    e:\documents and settings\renko\desktop\sonhazır\renko\mainfrm.cpp(16) : {77} client block at 0x00385300, subtype c0, 548 bytes long.
    a CMainFrame object at $00385300, 548 bytes long
    e:\documents and settings\renko\desktop\örnek\renko\renkodoc.cpp(17) : {76} client block at 0x00385268, subtype c0, 88 bytes long.
    a CrenkoDoc object at $00385268, 88 bytes long
    plex.cpp(27) : {75} normal block at 0x003851B0, 124 bytes long.
    Data: < (P8 > 00 00 00 00 00 00 00 00 00 00 00 00 28 50 38 00
    {74} client block at 0x00385150, subtype c0, 32 bytes long.
    a CDocManager object at $00385150, 32 bytes long
    {73} normal block at 0x003850D0, 61 bytes long.
    Data: < .|, , > 10 FF 2E 7C 2C 00 00 00 2C 00 00 00 01 00 00 00
    e:\documents and settings\renko\desktop\örnek\renko\renko.cpp(73) : {72} client block at 0x00385028, subtype c0, 108 bytes long.
    a CSingleDocTemplate object at $00385028, 108 bytes long
    {71} normal block at 0x00382EB8, 70 bytes long.
    Data: < .|4 5 > 10 FF 2E 7C 34 00 00 00 35 00 00 00 01 00 00 00
    {70} normal block at 0x00382E30, 70 bytes long.
    Data: < .|4 5 > 10 FF 2E 7C 34 00 00 00 35 00 00 00 01 00 00 00
    {69} normal block at 0x00382DB0, 63 bytes long.
    Data: < .|- . > 10 FF 2E 7C 2D 00 00 00 2E 00 00 00 01 00 00 00
    {68} normal block at 0x00382D28, 70 bytes long.
    Data: < .|4 5 > 10 FF 2E 7C 34 00 00 00 35 00 00 00 01 00 00 00
    {66} normal block at 0x00382C88, 23 bytes long.
    Data: < .| > 10 FF 2E 7C 06 00 00 00 06 00 00 00 01 00 00 00
    {65} normal block at 0x00382C28, 33 bytes long.
    Data: < .| > 10 FF 2E 7C 10 00 00 00 10 00 00 00 01 00 00 00
    {64} normal block at 0x00382BD8, 20 bytes long.
    Data: < 8-8 -8 @.8 > 04 00 00 00 38 2D 38 00 C0 2D 38 00 40 2E 38 00
    {63} normal block at 0x00382B78, 32 bytes long.
    Data: < - | +8 8,8 > E4 2D 15 7C 04 00 00 00 DC 2B 38 00 38 2C 38 00
    oleinit.cpp(85) : {60} client block at 0x00382A90, subtype c0, 68 bytes long.
    a CCmdTarget object at $00382A90, 68 bytes long
    {55} normal block at 0x003828F8, 2 bytes long.
    Data: <c > 63 00
    {48} client block at 0x003824F0, subtype c0, 64 bytes long.
    a CDynLinkLibrary object at $003824F0, 64 bytes long
    Object dump complete.
    First-chance exception at 0x7c901e58 in renko.exe: 0xC0000005: Access violation reading location 0x00000000.
    HEAP[renko.exe]: Invalid Address specified to RtlValidateHeap( 00380000, 00382918 )
    Unhandled exception at 0x7c8f1230 in renko.exe: User breakpoint.
    Unhandled exception at 0x1020a0d9 (msvcr70d.dll) in renko.exe: User breakpoint.
    HEAP[renko.exe]: Invalid Address specified to RtlFreeHeap( 00380000, 00382918 )
    Unhandled exception at 0x7c8f1230 in renko.exe: User breakpoint.
    Detected memory leaks!
    Dumping objects ->
    {55} normal block at 0x003828F8, 2 bytes long.
    Data: <c > 63 00
    Object dump complete.
    The thread 'Win32 Thread' (0xe9c) has exited with code 0 (0x0).
    The program '[3240] renko.exe: Native' has exited with code 0 (0x0).
    Reply With Quote
      #2    
    Old July 8th, 2005, 06:34 PM
    Jinto's Avatar
    Jinto Jinto is offline
    Member
     
    Join Date: Nov 2003
    Location: Seattle, WA
    Posts: 265
    Jinto is on a distinguished road (30+)
    Re: memory leaks

    Only way to prevent leaks is to make sure they never happen.
    Delete any resources you use when you are done with them.
    __________________
    "Lose it? It means go crazy...nuts...insane...bonzo...no longer in possession of one's faculties...3 fries short of a happy meal...WACKO!!!"
    Reply With Quote
      #3    
    Old July 9th, 2005, 03:44 AM
    amgturk amgturk is offline
    Junior Member
     
    Join Date: Jul 2005
    Posts: 15
    amgturk is an unknown quantity at this point (<10)
    Re: memory leaks

    yes ı know but as ı said the leaks matches with app wizard code..
    Reply With Quote
      #4    
    Old July 9th, 2005, 04:37 AM
    Andreas Masur Andreas Masur is offline
    Moderator
    Power Poster
     
    Join Date: May 2000
    Location: KY, USA
    Posts: 18,610
    Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)
    Re: memory leaks

    __________________
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)
    Reply With Quote
      #5    
    Old July 9th, 2005, 05:13 AM
    amgturk amgturk is offline
    Junior Member
     
    Join Date: Jul 2005
    Posts: 15
    amgturk is an unknown quantity at this point (<10)
    Re: memory leaks

    thanks mansur but ı already detected it..
    actually ı found that the real leakage is at another place..

    WCHAR tmp=new WCHAR(); as global.

    ıf ı use delete [] tmp in destruction function ı still have leakage.

    how can ı overcome?
    Reply With Quote
      #6    
    Old July 9th, 2005, 05:25 AM
    Andreas Masur Andreas Masur is offline
    Moderator
    Power Poster
     
    Join Date: May 2000
    Location: KY, USA
    Posts: 18,610
    Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)Andreas Masur has a brilliant future (2000+)
    Re: memory leaks

    Well..first of all it would be
    Code:
    WCHAR tmp= new WCHAR;
    delete tmp;
    Besides that....the MFC leak detection happens to at a specified time while closing the application. Since you allocate this memory globally, the leak detection most-likely has already happened before this variable gets deleted. This is of course just an assumption since I don't know the structure of your application...
    __________________
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)
    Reply With Quote
      #7    
    Old July 9th, 2005, 05:40 AM
    amgturk amgturk is offline
    Junior Member
     
    Join Date: Jul 2005
    Posts: 15
    amgturk is an unknown quantity at this point (<10)
    Re: memory leaks

    ok Masur maybe u can help by looking this function that is source of the problem.

    ı call this function in a loop about hundred times consecutively,ı tried to delete tmp at the end of function but this time another errors happen..

    WCHAR *tmp=new WCHAR; // as global

    void CrenkoView::imread(int im_indx)
    {
    int i, j;


    int redx = 0, redy = 0, redcount = 0;
    int redxavg = 0, redyavg = 0;


    int blackx = 0, blacky = 0, blackcount = 0;
    int blackxavg = 0, blackyavg = 0;


    //Sleep(50);


    GdiplusStartup (&m_gdiplusToken, &gdiplusstartupinput,NULL);





    swprintf(tmp, L"c:/Snapshot%d%d%d.jpg", im_indx/100, (im_indx%100)/10, im_indx%10);


    Bitmap *myBitmap = Bitmap::FromFile(tmp);



    Color clr;



    for(i=1; i<=320; i++)
    {
    for(j=1; j<=240; j++)
    {

    // Get the color codes of the (i, j)th pixel

    myBitmap->GetPixel(i,j,&clr);




    if( ((int)clr.GetRed() < 245 ) && ( (int)clr.GetGreen() <255 ) && ( (int)clr.GetBlue() <240 ) )
    {
    if( 50<((int)clr.GetRed() ) && 200<( (int)clr.GetGreen() ) && 185<( (int)clr.GetBlue() ) )
    {

    redx += i;
    redy += j;

    redcount++;
    }
    }


    ////////////////////////////////////////////////////////////////////////////////////

    if( ( (int)clr.GetRed() ) <255 && ( (int)clr.GetGreen()) <230 && ( (int)clr.GetBlue()) < 240 )
    {

    if( 200< ( (int)clr.GetRed() ) && 200 < ( (int)clr.GetGreen()) && 160 < ( (int)clr.GetBlue()) )
    {

    blackx += i;
    blacky += j;

    blackcount++;
    }
    }

    }
    }
    // myBitmap->GetPixel(300,400,&clr);
    // cout<<(int)clr.GetRed()<<endl;

    // Check if such colored objects even exist!

    if( redcount != 0)
    {

    redxavg=redx/redcount;
    redyavg=redy/redcount;

    }


    if( blackcount != 0)
    {

    blackxavg=blackx/blackcount;
    blackyavg=blacky/blackcount;

    }

    redxcoordinate[g]=redxavg;
    redycoordinate[g]=redyavg;

    blackxcoordinate[g]=blackxavg;
    blackycoordinate[g]=blackyavg;

    g++;



    delete myBitmap;
    //GdiplusShutdown(m_gdiplusToken);

    }
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Managed C++ and C++/CLI


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 06:03 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009