Doc/View application with docking pane
-
Hi, I have a Visual Studio 2008 MFC doc/view application. I have choosed a docking pane type. The dock is a tree control like Windows explorer. When I click an item on the tree, I want to change the form in the view area. For that I have to acces the document to get a member function. The code is working but I get memory leak. Perhaps I don't take the good way. Any suggestions ? Claude Here's my code: void CViewTree::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR); // TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle *pResult = 0; CString strItem; HTREEITEM hItem = GetSelectedItem(); strItem = GetItemText(hItem); // Pointeurs vers le document CFrameWnd *pFrameWnd = (CFrameWnd*)AfxGetApp()->m_pMainWnd; CCDSView* pView; pView = (CCDSView*)pFrameWnd->GetActiveView(); // // Detected memory leaks! //Dumping objects -> //{1272} normal block at 0x03E2C478, 530 bytes long. // Data: < 6 > 14 36 19 01 0F 00 00 00 00 01 00 00 01 00 00 00 //{1190} normal block at 0x03E28F20, 530 bytes long. // Data: < 6 ( > 14 36 19 01 28 00 00 00 00 01 00 00 01 00 00 00 //Object dump complete. CCDSDoc* pDoc = pView->GetDocument(); pDoc->ToDoc(strItem); }
-
Hi, I have a Visual Studio 2008 MFC doc/view application. I have choosed a docking pane type. The dock is a tree control like Windows explorer. When I click an item on the tree, I want to change the form in the view area. For that I have to acces the document to get a member function. The code is working but I get memory leak. Perhaps I don't take the good way. Any suggestions ? Claude Here's my code: void CViewTree::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR); // TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle *pResult = 0; CString strItem; HTREEITEM hItem = GetSelectedItem(); strItem = GetItemText(hItem); // Pointeurs vers le document CFrameWnd *pFrameWnd = (CFrameWnd*)AfxGetApp()->m_pMainWnd; CCDSView* pView; pView = (CCDSView*)pFrameWnd->GetActiveView(); // // Detected memory leaks! //Dumping objects -> //{1272} normal block at 0x03E2C478, 530 bytes long. // Data: < 6 > 14 36 19 01 0F 00 00 00 00 01 00 00 01 00 00 00 //{1190} normal block at 0x03E28F20, 530 bytes long. // Data: < 6 ( > 14 36 19 01 28 00 00 00 00 01 00 00 01 00 00 00 //Object dump complete. CCDSDoc* pDoc = pView->GetDocument(); pDoc->ToDoc(strItem); }
The code that you have shown does not appear to have any memory leaks. Search for the
new
keyword or functions likeHeapAlloc
,GlobalAlloc
,VirtualAlloc
etc. in all the code. Then you can see if the allocated memory is being freed. Alternatively you can use the_CrtMemCheckpoint
and_CrtMemDifference
functions to find exactly where the memory leak happens.«_Superman_» I love work. It gives me something to do between weekends.
-
Hi, I have a Visual Studio 2008 MFC doc/view application. I have choosed a docking pane type. The dock is a tree control like Windows explorer. When I click an item on the tree, I want to change the form in the view area. For that I have to acces the document to get a member function. The code is working but I get memory leak. Perhaps I don't take the good way. Any suggestions ? Claude Here's my code: void CViewTree::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR); // TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle *pResult = 0; CString strItem; HTREEITEM hItem = GetSelectedItem(); strItem = GetItemText(hItem); // Pointeurs vers le document CFrameWnd *pFrameWnd = (CFrameWnd*)AfxGetApp()->m_pMainWnd; CCDSView* pView; pView = (CCDSView*)pFrameWnd->GetActiveView(); // // Detected memory leaks! //Dumping objects -> //{1272} normal block at 0x03E2C478, 530 bytes long. // Data: < 6 > 14 36 19 01 0F 00 00 00 00 01 00 00 01 00 00 00 //{1190} normal block at 0x03E28F20, 530 bytes long. // Data: < 6 ( > 14 36 19 01 28 00 00 00 00 01 00 00 01 00 00 00 //Object dump complete. CCDSDoc* pDoc = pView->GetDocument(); pDoc->ToDoc(strItem); }
How do you know there is a memory leak? Is the debugger dumping the objects after your application shuts down? In which case it must point out the line numbers where the leaking memory was allocated. If not, you need to add this to the beginning of your manually created source files (if a source file is added by any of the wizards, it adds this by default):
#ifdef _DEBUG
#define new DEBUG_NEWYou may look at the definition of DEBUG_NEW to see what it does.
It is a crappy thing, but it's life -^ Carlo Pallini
-
Hi, I have a Visual Studio 2008 MFC doc/view application. I have choosed a docking pane type. The dock is a tree control like Windows explorer. When I click an item on the tree, I want to change the form in the view area. For that I have to acces the document to get a member function. The code is working but I get memory leak. Perhaps I don't take the good way. Any suggestions ? Claude Here's my code: void CViewTree::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR); // TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle *pResult = 0; CString strItem; HTREEITEM hItem = GetSelectedItem(); strItem = GetItemText(hItem); // Pointeurs vers le document CFrameWnd *pFrameWnd = (CFrameWnd*)AfxGetApp()->m_pMainWnd; CCDSView* pView; pView = (CCDSView*)pFrameWnd->GetActiveView(); // // Detected memory leaks! //Dumping objects -> //{1272} normal block at 0x03E2C478, 530 bytes long. // Data: < 6 > 14 36 19 01 0F 00 00 00 00 01 00 00 01 00 00 00 //{1190} normal block at 0x03E28F20, 530 bytes long. // Data: < 6 ( > 14 36 19 01 28 00 00 00 00 01 00 00 01 00 00 00 //Object dump complete. CCDSDoc* pDoc = pView->GetDocument(); pDoc->ToDoc(strItem); }