|
Could you, please help me! I'm developing with VC++ 6 (WinXP SP2) and now I'm trying to find memory leaks. Internal memory leak finder doesn't provide me with sufficient information about codelines etc. that is why I tried a lot of tools. No one helps me. Here you can see an example with VLD (http://www.codeproject.com/tools/visualleakdetector.asp) tool used. Here is the output in Debug window:
<br />
........<br />
Visual Leak Detector Version 1.0 installed (multithreaded static).<br />
Loaded 'G:\WINDOWS\system32\uxtheme.dll', no matching symbolic information found.<br />
Loaded 'G:\WINDOWS\system32\riched32.dll', no matching symbolic information found.<br />
........<br />
The thread 0x8D0 has exited with code 0 (0x0).<br />
The thread 0x17C has exited with code 0 (0x0).<br />
The thread 0xD2C has exited with code 0 (0x0).<br />
The thread 0x824 has exited with code 0 (0x0).<br />
The thread 0xCFC has exited with code 0 (0x0).<br />
The thread 0x8DC has exited with code 0 (0x0).<br />
The thread 0x5F8 has exited with code 561 (0x231).<br />
The thread 0x528 has exited with code 0 (0x0).<br />
The thread 0x294 has exited with code 2 (0x2).<br />
No memory leaks detected.<br />
Visual Leak Detector is now exiting.<br />
The thread 0x470 has exited with code 0 (0x0).<br />
No memory leaks detected.<br />
Visual Leak Detector is now exiting.<br />
Detected memory leaks!<br />
Dumping objects -><br />
{60} normal block at 0x02F71790, 12 bytes long.<br />
Data: < > 90 17 F7 02 90 17 F7 02 CD CD CD CD <br />
{59} normal block at 0x02F717D0, 44 bytes long.<br />
Data: <|h a a > 7C 68 F2 02 80 61 F2 02 88 61 F2 02 10 1B F7 02 <br />
Object dump complete.<br />
The thread 0x928 has exited with code 0 (0x0).<br />
The program 'E:\Devs\Camel\Debug\Camel.exe' has exited with code 0 (0x0).<br />
As you can see, VLD is saying that there are no memory leaks (1) then internal leaks finder is saying the same (2), but then it finds two leaks. How it can be and what is the problem? This problem is regardless tool used. I just placed VLD as an example. Tools like Insure++ find nothing at all of just lines with calls to rand() or time() , which have no attitude to the problem. What can it be?
|
|
|
|
|
dum wrote: What can it be?
Disclaimer: I have no experience with other leak detector tools except what VC++ alerts me to.
In my experience, typical leaks occur when I use BSTR without a wrapper, failure to release a device context(ReleaseDC) after using GetDC(), and the obvious new/delete mismatched pairs.
You should search for the obvious sources in your code first. Any usage of a raw BSTR should be considered suspect (Not necessarily bad but at least scrutinize who "owns" the BSTR) as well as GetDC() and all memory allocation.
The execution paths should be scrutinized as posted sample code usually makes many assumptions about the success of operations to keep the snippet short and can mislead proper robust deallocation schemes. For instance, allocating and deallocating within the same scope can be dangerous if there are potential execution paths that can skip over the deallocation. Try/Catch is one of the likely places to forget alternate execution paths when allocation/deallocation is involved.
I Hope that helps.
|
|
|
|
|
The fact is that I'm developing this code for... 5 years. There have been several official releases etc. All the time I could find leaks manully or using some tools. There are no BSTR's at all and no new resources occupations. I do not know, what can it be, because I don't undestand, how memory leaks can be detected after I was reported that "No memory leaks detected"? On what stage of application's execution it caould be in this case? May be one can recomend me some outstanding tool for leaks looking up (I have tryed 5 today and no one have helped)?
|
|
|
|
|
If it helps any, I took a mulithreaded app and placed some intentional leaks in one of three of the threads. Everything appears fine until the app exits and the main thread is being shut down. That is where I get my notification of a leak.
Again, I'm not familiar with 3rd party leak detection tools and how they report. I usually incrementally scrutinize any changes so I know what I just changed is likely causes any reported leaks.
What was the last thing modified in the code?
|
|
|
|
|
It seems to me that I have missed the exact biuld, when it appears exactly. So, now I need some tool or information to find out, how it could be so. As you can imagine, in my oppinion there are no fresh reasons for leaks
So, does someone can help?
|
|
|
|
|
Lets reformulate the question a bit: I know the address, that leaks. I need a tool, which can tell me (after the execution of application), which line allocates at this address. Who knows such thing?
|
|
|
|
|
I haven't used VLD, but i expect that i creates a global instance of an class that checks for leaks in it's destructor.
I would also expect that there hasn't been any effort to control at what point the global object is created.
I would guess that there is a global object that is being created before VLD is initialized.
When when VLD exits all memory allocated since it was initialized has been freed, it knows nothing about memory allocated before it was initialized (so it says no leaks).
Your internal is likely the same.
So, depending on what you are calling that actually generates the leak message, you may have a leak in a global that is initialized early, or you may not have a leak at all just mis-configured leak detection code.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Thanx, but I do not think so.
1) Even without VLD I'm gettint "No leaks" and then a report about leaks from internal finder
2) I do not regulate the moment, whan VLD is created. It is kind of "p'n'p" solution: I just include it, no changes to code.
Does anyone have more ideas?
|
|
|
|
|
I don't know about third-party leak detectors.
I do use the CRT heap debugging features in my debug builds.
This goes on top (under the (#include lines) of all my source files:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
For leaks that still don't give file/line number info...
In the debug output for the leaks, if the number in the curly braces is the same every time
you can add a breakpoint to break when those allocations occur.
See How to: Set Breakpoints on a Memory Allocation Number[^]
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thank you for the information, it is very interesting, but the problem again. All the time I'm getting problem on allocations 59 and 60.
{60} normal block at 0x02721790, 12 bytes long.<br />
Data: < r r > 90 17 72 02 90 17 72 02 CD CD CD CD <br />
{59} normal block at 0x027217D0, 44 bytes long.<br />
Data: <|hm am am r > 7C 68 6D 02 80 61 6D 02 88 61 6D 02 10 1B 72 02 <br />
Object dump complete.<br />
but _CrtSetBreakAlloc(60); results in no break. Why can it be? I'm using VC++ 6, but there are no reasons to assume that it doesn't support this function.
|
|
|
|
|
I want to download the latest platform SDK for visual c++ based development. If I use google to locate it, I am being taken to a page at Microsoft which says Windows 2003 server sdk. If I search MS for SDK, there are plenty of results and I am confused. Can someone give me a link where I could download the latest platform SDK? Thanks.
Sorry if it is posted twice. There was error, when I attempted previously. I will delete one, if it is posted twice.
|
|
|
|
|
Windows Server 2003 R2 sdk
that is to the best of my knowneldge is the latest sdk for vc++ developers
p.s its name is a bit miss leading but thats the one
|
|
|
|
|
If you're using VS05, the latest & greatest SDK is now called the Windows SDK[^].
|
|
|
|
|
looks like i need to upgrade my SDK
thanks
|
|
|
|
|
Ive looked around on getting inputs from the LPT port on windows xp, apparantly I need a dll called inpout32.dll. I have that, however I wonder how I should "include" the file? So that i can use the code described on http://www.ctv.es/pckits/tutorial.html#ppro and its functions
Ive looked around alot on codeproject, and google around 50 times, but not found how to get it to work...
any ideas?
Im open to other methods too, but nothing too advanced.
PS, im in win32console with mfc on winxp, i will only be using lpt inputs, two of them.
thanks!
//Johannes
|
|
|
|
|
I've developed a program that performs some mathematical operations and then exports the results into a csv file to be opened with Excel.
To export the results I used a while loop with incremental values and that's fine but now I'd like to save (and read) some results in (or from) very specific locations (e.g. 6th case of the 2nd row).
I am using C++ and the Win32 Console application in VS2005.
Does anybody know how to do that?
Many thanks for your help.
|
|
|
|
|
J_E_D_I wrote: ...I'd like to save (and read) some results in (or from) very specific locations (e.g. 6th case of the 2nd row).
Without also writing to the first row, and the other five cases of the second row?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Correct!
Is it possible to read and write to and from very specific locations leving the rest unchanged?
I will be happy only when I will have FULL contol over this nasty language!
|
|
|
|
|
J_E_D_I wrote: Is it possible to read and write to and from very specific locations leving the rest unchanged?
Probably, but I would find it a lot easier to read the file into some sort of data structure, make the necessary changes, and write the data structure back to disk.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi all,
I am transferring to .NET 2003 to .NET 2005 now. I have one application made in Visual C++.NET 2003. It is compiling fine in .NET 2005 but it gives one run time error at ShowDialog() function of OpenFileDialog Class object. Error is
"An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll
Additional information: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."
Can I know what is wrong with this? And how can I solve this problem.
Thanks in advance,
Priyank
|
|
|
|
|
This should be posted on the Managed C++/CLI board.
I'm not sure what threads have to do with using the OpenFileDialog, but the error message is
pretty descriptive - it even states how to fix it.
Which version of ShowDialog() are you using?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
"Ensure that your Main function has STAThreadAttribute marked on it."
Have you tried this?
|
|
|
|
|
Are you switching to the "dark side of the force"?
Steve
|
|
|
|
|
I think Mike's onto something here; the error message is describing exactly what's wrong. See here[^] for more details.
Steve
|
|
|
|
|
I am using Visual Studio 2005, with Visual C++, and have generated a single docuemnt project with mainframe and childview for MFC.
I want to display parts of an image that the program loads from a bitmap file, on a grid pattern as produced by CGrid class in Grid.h and Grid.cpp.
When I use the StretchBlt function, the program asks for a HDC!!!!
I have not found litterature or samples for the use of that device context.
Would you know of a solution?
Thanks for any help....
Here is a possible code section for my function. With it, I can enter a string but not the image. It creates a CDC* but not a HDC. How should I code the HDC?????
void CGrid::FillCell(int r, int c, CString val, COLORREF brushColor, CImage m_Image)
{
CWnd* pWnd = AfxGetMainWnd();
CDC* pDC = pWnd->GetDC();
// pDC->BitBlt(0,0,20,20,pDC,0,0,SRCCOPY);
CBrush* pBrush;
pBrush = new CBrush (brushColor);
pDC->FillRect (mGrid[r][c],pBrush );
delete pBrush;
pDC->SetBkMode (TRANSPARENT);
pDC->SetTextColor (mStringColor);
pDC->DrawText(val,-1,mGrid[r][c],
DT_SINGLELINE |
DT_CENTER |
DT_VCENTER
);
// m_Image.StretchBlt(pDC,mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),SRCCOPY);
// pDC->StretchBlt(mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),m_Image,mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),SRCCOPY);
pWnd->ReleaseDC(pDC);
}
guybour
|
|
|
|