Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Memory Leak In this function?

Memory Leak In this function?

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestionannouncement
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    szcococut
    wrote on last edited by
    #1

    BOOL GetHistory() { STATURL url; CString strUrl; ULONG uFetched; IUrlHistoryStg2Ptr history; IEnumSTATURLPtr enumPtr; if(FAILED(CoCreateInstance(CLSID_CUrlHistory, NULL, CLSCTX_INPROC_SERVER, IID_IUrlHistoryStg2,(void**)&history))) { return false; } if(FAILED(history->EnumUrls(&enumPtr))) { history->Release(); return false; } while(SUCCEEDED(enumPtr->Next(1,&url,&uFetched))) { if(uFetched==0) break; } history->Release(); return true; } if I set a timer to call the function ,the memory leak if I delete while(SUCCEEDED(enumPtr->Next(1,&url,&uFetched))) { if(uFetched==0) break; } memory is good ! why? thanks!

    S 1 Reply Last reply
    0
    • S szcococut

      BOOL GetHistory() { STATURL url; CString strUrl; ULONG uFetched; IUrlHistoryStg2Ptr history; IEnumSTATURLPtr enumPtr; if(FAILED(CoCreateInstance(CLSID_CUrlHistory, NULL, CLSCTX_INPROC_SERVER, IID_IUrlHistoryStg2,(void**)&history))) { return false; } if(FAILED(history->EnumUrls(&enumPtr))) { history->Release(); return false; } while(SUCCEEDED(enumPtr->Next(1,&url,&uFetched))) { if(uFetched==0) break; } history->Release(); return true; } if I set a timer to call the function ,the memory leak if I delete while(SUCCEEDED(enumPtr->Next(1,&url,&uFetched))) { if(uFetched==0) break; } memory is good ! why? thanks!

      S Offline
      S Offline
      Steen Krogsgaard
      wrote on last edited by
      #2

      You must free STATURL.pwcsUrl and STATURL.pwcsTitle after each call to enumPtr->Next. MSDN says so. Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

      S 1 Reply Last reply
      0
      • S Steen Krogsgaard

        You must free STATURL.pwcsUrl and STATURL.pwcsTitle after each call to enumPtr->Next. MSDN says so. Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

        S Offline
        S Offline
        szcococut
        wrote on last edited by
        #3

        to Steen Krogsgaard how to free STATURL.pwcsUrl and STATURL.pwcsTitle can you tell me?

        T S 2 Replies Last reply
        0
        • S szcococut

          to Steen Krogsgaard how to free STATURL.pwcsUrl and STATURL.pwcsTitle can you tell me?

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          don't you do it like this ?

          delete STATURL.pwcsUrl;
          delete STATURL.pwcsTitle;


          TOXCCT >>> GEII power
          [toxcct][VisualCalc]

          S 1 Reply Last reply
          0
          • T toxcct

            don't you do it like this ?

            delete STATURL.pwcsUrl;
            delete STATURL.pwcsTitle;


            TOXCCT >>> GEII power
            [toxcct][VisualCalc]

            S Offline
            S Offline
            szcococut
            wrote on last edited by
            #5

            I try like this: delete STATURL.pwcsUrl; delete STATURL.pwcsTitle; but I get an excetion!

            T 1 Reply Last reply
            0
            • S szcococut

              I try like this: delete STATURL.pwcsUrl; delete STATURL.pwcsTitle; but I get an excetion!

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              szcococut wrote:

              but I get an excetion!

              i believe you get a ComplainNotExplainedEnoughException, don't you ? ;P please provide us the infos if you want so help...


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              1 Reply Last reply
              0
              • S szcococut

                to Steen Krogsgaard how to free STATURL.pwcsUrl and STATURL.pwcsTitle can you tell me?

                S Offline
                S Offline
                Steen Krogsgaard
                wrote on last edited by
                #7

                LPMALLOC lpMalloc; CoGetMalloc(1, &lpMalloc); lpMalloc->Free(url.pwcsUrl); lpMalloc->Free(url.pwcsTitle); lpMalloc->Release(); or CoTaskMemFree(url.pwcsUrl); CoTaskMemFree(url.pwcsTitle); The two methods are analogous (actully, identical, CoTaskMemFree calls CoGetMalloc and IMalloc->Free). Add error handling for flavor. Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

                S 1 Reply Last reply
                0
                • S Steen Krogsgaard

                  LPMALLOC lpMalloc; CoGetMalloc(1, &lpMalloc); lpMalloc->Free(url.pwcsUrl); lpMalloc->Free(url.pwcsTitle); lpMalloc->Release(); or CoTaskMemFree(url.pwcsUrl); CoTaskMemFree(url.pwcsTitle); The two methods are analogous (actully, identical, CoTaskMemFree calls CoGetMalloc and IMalloc->Free). Add error handling for flavor. Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

                  S Offline
                  S Offline
                  szcococut
                  wrote on last edited by
                  #8

                  thanks Steen ! it just What I want!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups