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