CEditView -> CEdit::ReplaceSel() leaks GDI Objects?
-
I have an MDI app using CEditView in the Doc/View architecture. In this view, I have a function like so, which I call from the Document class: void CMyEditView::addText(LPCTSTR szOutput) { ASSERT_VALID(this); int nSize = GetBufferLength(); GetEditCtrl().SetSel(nSize, nSize, TRUE); GetEditCtrl().ReplaceSel(szOutput, FALSE); } After feeding it data for a while, the program inevitably crashes and the display gets corrupted. By watching the executable's resources in Task Manager, I notice that the GDI Objects are steadily increasing, until they reach 9999, and then the crash happens. By setting breakpoints, I can see that one GDI Object is consumed every time CEdit::ReplaceSel() is called, and never released. Is this method for appending text to an Edit Control contained in a View appropriate? Anyone know a better way? Using GetWindowText() and SetWindowText() has the same problem! Any thoughts as to what's happening, and how I can prevent the resource loss? Thanks ! scott sanders
-
I have an MDI app using CEditView in the Doc/View architecture. In this view, I have a function like so, which I call from the Document class: void CMyEditView::addText(LPCTSTR szOutput) { ASSERT_VALID(this); int nSize = GetBufferLength(); GetEditCtrl().SetSel(nSize, nSize, TRUE); GetEditCtrl().ReplaceSel(szOutput, FALSE); } After feeding it data for a while, the program inevitably crashes and the display gets corrupted. By watching the executable's resources in Task Manager, I notice that the GDI Objects are steadily increasing, until they reach 9999, and then the crash happens. By setting breakpoints, I can see that one GDI Object is consumed every time CEdit::ReplaceSel() is called, and never released. Is this method for appending text to an Edit Control contained in a View appropriate? Anyone know a better way? Using GetWindowText() and SetWindowText() has the same problem! Any thoughts as to what's happening, and how I can prevent the resource loss? Thanks ! scott sanders
-
I created a simple MDI application as you described and - using the same code you wrote - the GDI objects are changing between 31 and 32. It looks ok. Where is that
szOutput
coming from? rechiThank you for your reply ! After experimenting a bit more, I found out that the resource leak was actually coming from my CMyView::CtlColor() function. I was allocating a brush to change the background color of the window, depending on the program state, and never releasing it. So it was my silly fault all along; sorry to send you on a wild goose chase. I changed the brush to be static, and the problem disappeared. Thanks again for looking into this for me. scott
-
Thank you for your reply ! After experimenting a bit more, I found out that the resource leak was actually coming from my CMyView::CtlColor() function. I was allocating a brush to change the background color of the window, depending on the program state, and never releasing it. So it was my silly fault all along; sorry to send you on a wild goose chase. I changed the brush to be static, and the problem disappeared. Thanks again for looking into this for me. scott