|
Ah, well, lets go back to the leak then.
If you're using a typical MFC dialog based app, make a note of the allocation number of the leak from the object dump.
Start the program again with F10. Open the watch window, and enter this variable name:
{,,msvcrtd.dll}*__p__crtBreakAlloc()
If it shows a -1, you're in luck. Enter the value of the allocation that leaked, and the program will break when its allocated - and you can just hop up the call stack to see whats leaking.
Basically, if you use new you need to use delete to free the memory allocated - but sometimes its tricky to determine where the leak occurred.
Note that sometimes {,,msvcrtd.dll}*__p__crtBreakAlloc() doesn't show up - _ctrBreakAlloc may work.
The allocation number of the dump is the one in curly braces in an output like this:
E:\Develop(Tim)\OPCSim1\OPCSim1.cpp(51) : {64} normal block at 0x00300030, 1 bytes long.
Data: < > CD
|
|
|
|
|
Excuse my ignorance, how can I get the allocation number,
and where do I input it?
I did look at "{,,msvcrtd.dll}*__p__crtBreakAlloc()", and
it did come up -1.
On a separate note, if I declare a GDIObject, say...
CBrush testBrush;
Should I explicitly delete it when I'm done with the object?
(Given that I did save the original CBrush and restored it
to the CDC when I was finished. More specifically, I'm using
SaveDC and RestoreDC)
If I don't delete the object, do GDIObjects have their own "safe"
destructors?
Regards,
-t²
|
|
|
|
|
Oh - ok - I make a distiction between resource leaks and memory leaks - perhaps what you have is a resource leak.
If you are working with classes derived from CGdiObject (like CBrush, CPen) the ~CGdiObject destructor should free the resource for you - so when the testBrush goes out of scope, or its containing class is destroyed, you should be ok. MFC will ASSERT in debug mode if you try to call CreateBrush or CreatePen twice without calling DeleteObject.
If you are working with handles returned from say, a call to ::CreateBrushIndirect (not using CBrush) you must be careful to destroy the object (after deselecting it from the DC).
What is telling you that you have the leak? - I thought it was a dump provided by the debug C runtime allocation routines - in which case the allocation number would be the one in curly braces.
Say - since this thread is getting kind of buried now, why don't you post a bit of code (showing your SaveDC and RestoreDC calls and stuff that you are doing in between) in a new thread - rem - use <pre> and </pre> to surround your code - if its a resource leak, it may not be obvious - I seem to recall some subtle gotchas that have appeared in these posts - but I bet you'll get a helpful answer real quick.
|
|
|
|
|
I placed a followup on our discussion in a new thread...
"CDC Resource/Memor Leaks... (continued)..."
-t²
|
|
|
|
|
I have several static controls that are mapped to CString member variables.. I have a clear function that sets all the CString member variables to "".. When I execute "OnClear" all my edit boxes and combo boxes clear but my static controls do not clear unless I minimize then maximize the dialog box. Any ideas on how I can repaint the dialog box to reflect the new values.. I do a UpdateData(FALSE) at the end of my clear function.
Thanks,
Rob
|
|
|
|
|
Call RedrawWindow() on your dialog to make it repaint.
--Mike--
http://home.inreach.com/mdunn/
Trillian: What are you supposed to do with a manically depressed robot?
Marvin: You think you've got problems. What are you supposed to do if you are a manically depressed robot?
|
|
|
|
|
Hello, the codegurus around the world.;)
Try to SetWindowText() to update the text for Static control.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
I have tried both methods and neither are working. It may be because the background of my dialog is a bitmap. I have opened spy++ and am trying to find the function that they use to redraw the whole dialog when I go from minimized to maximize.. The RedrawWindow() may be the ticket, as of right now I have only tried RedrawWindow() with out any parameters. I’ll play around with it to see if I can get it to work.
Thank you both for your responses.
Rob
|
|
|
|
|
Never mind the last reply.. RedrawWindow() works fine.. I was calling UpdateData(FALSE); after the RedrawWindow()..
Everything is working great!!
Thanks!
Rob
|
|
|
|
|
Please, check your DoDataExchange() function,
It may look like this
void CDlgStatic::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgStatic)
DDX_Text(pDX, IDC_STATIC_1, m_Static);
...........
//}}AFX_DATA_MAP
}
In general, there is no need to repaint the control.
|
|
|
|
|
My DoDataExchange() function does look exactly like you posted.. Should it look different?
The repaint is working fine for me..
Thanks,
Rob
|
|
|
|
|
What ure doing should work, i cant see why it don't! Anyway try doing what folows:
CRect clientRect;
GetClientRect(clientRect);
InvalidateRect(clientRect);
that should do it!
Good luck!
Papa Charchabil.
|
|
|
|
|
Hi,
I am looking for the font responsible
to display the tree symbols in the
upper right corner of a window.
On my computer, these symbols are
replaced by 0, 1 and r.
Any suggestions ?
Claude
|
|
|
|
|
|
Hello,
Can somebody give me the advantages/disadvantages of using VB to develop COM component instead of using ATL to do the same. Any links to such comparisons are also appreciated.
Ganesh.M.Ramaswamy
|
|
|
|
|
You can create COM components in VB ?
ATL was created to make it easy to create lean, mean COM components. Visual Basic was created to make it easy for monkeys to get a window on the screen and access lean, mean COM components that do all the work. Which do you think will be better ?
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I've only limited experience with creating VB COM objects but I find that it feels more like a hack rather than a useful feature. ATL is far superior because it was designed to create COM components.
Creating an ActiveX control with Visual Basic is easier and hides some of the hardwork from you.
If you know C++ then I'd stick with using ATL.
Michael
|
|
|
|
|
Hello everybody!
Help me, please.
How can I print to the printer the rectangle which has been filled with a brush, another than pattern brush?
|
|
|
|
|
You're not using MFC ? If you're using MFC and Doc/View, then your only problem is getting the rectangle to scale to the size of the printers device context, otherwise all you will print is a little speck.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
hi,
i have a problem with the macro IMPLEMENT_SERIAL.
Because my class TempClass is Template and when i try to insert the macro
into the .h file, the compiler says i have to write the arguments of TempClass.
Does someone have an idea ?
Here's the code :
*******************************************
template<class t="">
class TempClass : public Msg
{
DECLARE_SERIAL(TempClass )
TempClass();
~TempClass();
//here the rest of class declaration...
virtual void Serialize (CArchive& ar);
};
IMPLEMENT_SERIAL(TempClass ,Msg,1) //it crashes here
template<class t="">
TempClass <t>::TempClass ()
{
...
}
...
|
|
|
|
|
Sorry - you can't use MFC runtime type information with templates. IMPLEMENT_SERIAL/DYNCREATE/DYNAMIC will not work - that's because MFC creates some global variables named after your class name. With templates it simply doesn't work.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Many Thanks for your respond, it will avoid me long hours of research )
|
|
|
|
|
Sirs,
do you know how to create a property sheet or even a simple dialog in one pane of an SDI splitter window?
I have tried following code:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
{
//creating 1 row and 2 cols
BOOL bCreateSplitter= m_wndSplitter.CreateStatic(this, 1, 2);
//creating views
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CFirstView),CSize(100,100), pContext);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CSecondView), CSize(100,100), pContext);
return bCreateSpltr;
}
where CFristView and CSecondView are generated by the class wizard, and FirstView.h and SecondView.h are included in MainFrm.h.
When CFristView and CSecondView are derived from CView everything is OK, it compiles and runs OK.
When the panes base class is a CFormView or CPropertySheet then it compiles though but asserts before creation of mainframe. When the base class is a CDialog or CWnd the code does not even compile ("classCFirstView is not a member of CFirstView").
Thank you for your help in advance.
Bunburry
Education is an admirable thing but it is well to remember from time to time that nothing that is worth knowing can be taught (O.Wilde)
|
|
|
|
|
Are you sure your IMPLEMENT_DYNCREATE has the right arguments when you change the base class? Also pay attention to the message map macro BEGIN_MESSAGE_MAP.
To be sure you correctly replaced the base class use the "Replace" command in VS.
Paolo.
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|
Hi @ all
I'm doing an internship in a software company. One of my tasks is testing modules.
After seperatly compiling the modules I get objectfiles, exe files and so on.
So where can I get some information about linking the seperate parts (to create several test scenarios)? Could anybody help me with the link.exe options (perhaps a link to a good documentation or example)?
Thanks a lot
|
|
|
|