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. CFileFind allocates memory but does not release it?

CFileFind allocates memory but does not release it?

Scheduled Pinned Locked Moved C / C++ / MFC
questionalgorithmsperformancehelpannouncement
6 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.
  • R Offline
    R Offline
    ryuki
    wrote on last edited by
    #1

    I had some trouble with my app because it allocates a lot of memory. The longer you use it the more memory was eaten away. After searching for a reason I endet up with CFindFile as the only reason for that. I have a loop and after deleting all but the CFileFind calls it is the only think that keeps running and allocating memory. Unfortunately CFileFind seems to not release the memory it uses. I tried everything: CFindFile* findfile=new CFindFile(); //... searching files findfile->Close(); delete findfile; doesn't release any of the allocated memory. Can someone help me? How can I free the allocated memory. Is there a alternate way to search for files in a directory?

    D 1 Reply Last reply
    0
    • R ryuki

      I had some trouble with my app because it allocates a lot of memory. The longer you use it the more memory was eaten away. After searching for a reason I endet up with CFindFile as the only reason for that. I have a loop and after deleting all but the CFileFind calls it is the only think that keeps running and allocating memory. Unfortunately CFileFind seems to not release the memory it uses. I tried everything: CFindFile* findfile=new CFindFile(); //... searching files findfile->Close(); delete findfile; doesn't release any of the allocated memory. Can someone help me? How can I free the allocated memory. Is there a alternate way to search for files in a directory?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      There is no reason to use a heap variable here. Use a stack variable and your memory-related problems will stop. ryuki wrote: doesn't release any of the allocated memory. Actually it does, but you are confused as to what happens with memory once it is freed. If you are using Task Manager to watch your program's memory drop after each call to free, you will surely be disappointed.


      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

      R 1 Reply Last reply
      0
      • D David Crow

        There is no reason to use a heap variable here. Use a stack variable and your memory-related problems will stop. ryuki wrote: doesn't release any of the allocated memory. Actually it does, but you are confused as to what happens with memory once it is freed. If you are using Task Manager to watch your program's memory drop after each call to free, you will surely be disappointed.


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        R Offline
        R Offline
        ryuki
        wrote on last edited by
        #3

        I work under Win98 and use the systemmonitor for viewing allocated memory. Its not easy to say but there seems to be more to the memory issue than expected. I managed to find another source of consuming memory. It is a little part including SHGetFileInfo. And that small codebit causes much more trouble than all other together. It seems that SHGetFileInfo allocates memory too. But you can't see it at the systemmonitor. It eats all of it with time and at a single point I can't create threads anymore or some functions like StretchDIBits doesn't work properly because there is no memory anymore. I get a lot of "Not enough memory" errors allthough all ressourceviewers say there are more than 100 MB of free memory still there. I can give you the small code example: SHFILEINFO sfi; UINT uFlags = SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME | SHGFI_ICON | SHGFI_SMALLICON; if ( SHGetFileInfo ( tmp, 0, &sfi, sizeof(SHFILEINFO), uFlags )) m_ctrPathFrom->InsertItem ( npos, sfi.szDisplayName, sfi.iIcon ); Thats all. I looked at the documentation but it says nothing about freeing the structure or something. Does someone know what to do? And you can be believe me, i traced the cause of the memory issue to that single if-line. I hope someone can help.

        P 1 Reply Last reply
        0
        • R ryuki

          I work under Win98 and use the systemmonitor for viewing allocated memory. Its not easy to say but there seems to be more to the memory issue than expected. I managed to find another source of consuming memory. It is a little part including SHGetFileInfo. And that small codebit causes much more trouble than all other together. It seems that SHGetFileInfo allocates memory too. But you can't see it at the systemmonitor. It eats all of it with time and at a single point I can't create threads anymore or some functions like StretchDIBits doesn't work properly because there is no memory anymore. I get a lot of "Not enough memory" errors allthough all ressourceviewers say there are more than 100 MB of free memory still there. I can give you the small code example: SHFILEINFO sfi; UINT uFlags = SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME | SHGFI_ICON | SHGFI_SMALLICON; if ( SHGetFileInfo ( tmp, 0, &sfi, sizeof(SHFILEINFO), uFlags )) m_ctrPathFrom->InsertItem ( npos, sfi.szDisplayName, sfi.iIcon ); Thats all. I looked at the documentation but it says nothing about freeing the structure or something. Does someone know what to do? And you can be believe me, i traced the cause of the memory issue to that single if-line. I hope someone can help.

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          From MSDN: [quote] Remarks If SHGetFileInfo returns an icon handle in the hIcon member of the SHFILEINFO structure pointed to by psfi, you are responsible for freeing it with DestroyIcon when you no longer need it. [/quote]


          sig test

          R 1 Reply Last reply
          0
          • P PJ Arends

            From MSDN: [quote] Remarks If SHGetFileInfo returns an icon handle in the hIcon member of the SHFILEINFO structure pointed to by psfi, you are responsible for freeing it with DestroyIcon when you no longer need it. [/quote]


            sig test

            R Offline
            R Offline
            ryuki
            wrote on last edited by
            #5

            Thank you for the hint. I use the standart documentation, the msdn library coming with VC++ 6. Next Time I will check the online docu too.

            D 1 Reply Last reply
            0
            • R ryuki

              Thank you for the hint. I use the standart documentation, the msdn library coming with VC++ 6. Next Time I will check the online docu too.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              ryuki wrote: ...the msdn library coming with VC++ 6. Which is nearly five years old.


              "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

              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