Debug assertion failed
-
How do i release the memory after reading from the CList from the head position.If i run the folowing code i get Debug assertion failed at the delete statement. void CPLayerApp::LockIt() { unsigned char data[10], mCnt,mMid; CMessage* pMess; CSingleLock singleLock(&m_SyncLock.m_mutex); CString str=""; while(1) { if(m_messList.GetCount() != 0) { singleLock.Lock(); pMess = &m_messList.GetAt(m_messList.GetHeadPosition());//m_messList is a CList pointer mCnt = pMess->m_cnt; mMid = pMess->m_mid; pMess->GetData(data); POSITION pos = m_messList.GetHeadPosition(); m_messList.RemoveHead(); delete pos; singleLock.Unlock(); if(data[0] == 0x10) { str.Format("%0x",data[0]); AfxMessageBox(str); break; } } Sleep(200); } Rsh
-
How do i release the memory after reading from the CList from the head position.If i run the folowing code i get Debug assertion failed at the delete statement. void CPLayerApp::LockIt() { unsigned char data[10], mCnt,mMid; CMessage* pMess; CSingleLock singleLock(&m_SyncLock.m_mutex); CString str=""; while(1) { if(m_messList.GetCount() != 0) { singleLock.Lock(); pMess = &m_messList.GetAt(m_messList.GetHeadPosition());//m_messList is a CList pointer mCnt = pMess->m_cnt; mMid = pMess->m_mid; pMess->GetData(data); POSITION pos = m_messList.GetHeadPosition(); m_messList.RemoveHead(); delete pos; singleLock.Unlock(); if(data[0] == 0x10) { str.Format("%0x",data[0]); AfxMessageBox(str); break; } } Sleep(200); } Rsh
-
How do i release the memory after reading from the CList from the head position.If i run the folowing code i get Debug assertion failed at the delete statement. void CPLayerApp::LockIt() { unsigned char data[10], mCnt,mMid; CMessage* pMess; CSingleLock singleLock(&m_SyncLock.m_mutex); CString str=""; while(1) { if(m_messList.GetCount() != 0) { singleLock.Lock(); pMess = &m_messList.GetAt(m_messList.GetHeadPosition());//m_messList is a CList pointer mCnt = pMess->m_cnt; mMid = pMess->m_mid; pMess->GetData(data); POSITION pos = m_messList.GetHeadPosition(); m_messList.RemoveHead(); delete pos; singleLock.Unlock(); if(data[0] == 0x10) { str.Format("%0x",data[0]); AfxMessageBox(str); break; } } Sleep(200); } Rsh
Actually the statement of 'delete pos' doesnt make sense !! pos is just a stack variable and its value is not necessarily a pointer.
-
Actually the statement of 'delete pos' doesnt make sense !! pos is just a stack variable and its value is not necessarily a pointer.
-
Ok. If POSITION and pos r not required can u pls. suggest how to release the memory associated with the element in the CList after you read that? Cause RemoveHead()is not doing that. Rsh
how abt 'delete pMess' ???
-
how abt 'delete pMess' ???
-
No Prem, even that doesn't work.Just now i tried with that also. Its giving the same error. Rsh
-
How do i release the memory after reading from the CList from the head position.If i run the folowing code i get Debug assertion failed at the delete statement. void CPLayerApp::LockIt() { unsigned char data[10], mCnt,mMid; CMessage* pMess; CSingleLock singleLock(&m_SyncLock.m_mutex); CString str=""; while(1) { if(m_messList.GetCount() != 0) { singleLock.Lock(); pMess = &m_messList.GetAt(m_messList.GetHeadPosition());//m_messList is a CList pointer mCnt = pMess->m_cnt; mMid = pMess->m_mid; pMess->GetData(data); POSITION pos = m_messList.GetHeadPosition(); m_messList.RemoveHead(); delete pos; singleLock.Unlock(); if(data[0] == 0x10) { str.Format("%0x",data[0]); AfxMessageBox(str); break; } } Sleep(200); } Rsh
:confused: Are you just trying to iterate through the list? If so, there are easier ways, I will elaborate if needed. Otherwise, just remove the line that says 'delete pos;'. As was stated this is a variable declared on the stack. Trying to delete it will cause debug assertion errors. (Worse yet in release mode)
-
:confused: Are you just trying to iterate through the list? If so, there are easier ways, I will elaborate if needed. Otherwise, just remove the line that says 'delete pos;'. As was stated this is a variable declared on the stack. Trying to delete it will cause debug assertion errors. (Worse yet in release mode)
what exactly i want is, to read the elemnts from the headposition in Clist and immediately after reading,would like to delete the already read element from the list & also release the memory that was associated with the deleted element. Can anybody pls. elaborate on this The code is as follows void CPLayerApp::LockIt() { unsigned char data[10],mCnt,mMid; unsigned char *ptr; CMessage* pMess; CMessage* delMess; CSingleLock singleLock(&m_SyncLock.m_mutex); CString str=""; while(1) { if(m_messList.GetCount() != 0) { singleLock.Lock(); pMess = &m_messList.GetAt(m_messList.GetHeadPosition()); mCnt = pMess->m_cnt; mMid = pMess->m_mid; pMess->GetData(data); //POSITION pos = m_messList.GetHeadPosition(); m_messList.RemoveHead(); delMess= &m_messList.RemoveHead(); //pMess=(CMessage*)m_messList.RemoveHead(); delete delMess; singleLock.Unlock(); if(data[0] == 0x10) { str.Format("%0x",data[0]); AfxMessageBox(str); break; } } Sleep(200); }:( Rsh