Re: Memory problems when deleting a vector element

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




Sorry, mistake while copy pasting...

Correction:
typedef vector <entry*> tbl;

On Jun 13, 1:47 pm, newbee <c.sun...@xxxxxxxxx> wrote:
That is the actual code. It compiles fine, and most of the time if
runs fine as well. I did not write the code, but I am getting an
exception from this line. This is the trace:

MSVCRTD!_free_dbg+0x41
MFC42D!operator delete+0xf
MFC42D!CString::FreeData+0x18
MFC42D!CString::~CString+0x39
AppName!entry::~entry+0x53
AppName!entry::'scalar deleting constructor'+0x25
AppName!X::delete_owned+0xf7
....................................

delete_owned() is the function above that contains the offending
line.

Looks like the problem happens when it tries to delete the CString
func_name, but I don't know why.
While deleting the entry in the vector, I guess it might be better to
use some itertator to the vector, but that still doesn't explain my
Debug Assertion, which is either of the type
"_CrtIsValidHeapPointer(pUserData)", or "_BLOCK_TYPE_IS_VALID(pHead-

nBlockUse)"

Thanks.

On Jun 13, 1:01 pm, "Igor Tandetnik" <itandet...@xxxxxxxx> wrote:



newbee <c.sun...@xxxxxxxxx> wrote:
typedef struct {
CString func_name;
list req_list;
int owner_id;
void *p_func;
} entry;

typedef vector <entry> tbl;

class X
{...
tbl m_table;
}

In one of the member functions of Class X, occasionally, the operator
delete for CString for the "delete m_table[i]" line gives a problem.

The statement

delete m_table[i];

shouldn't even compile, since m_table[i] is not a pointer, but is of
type entry&. Show your actual code.

Also, define "gives a problem". What specificially goes wrong, and in
exactly what way?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -


.



Relevant Pages

  • Re: Memory problems when deleting a vector element
    ... It compiles fine, and most of the time if ... Looks like the problem happens when it tries to delete the CString ... While deleting the entry in the vector, I guess it might be better to ... type entry&. ...
    (microsoft.public.vc.language)
  • Re: How to get PR_ENTRYID for the newly created IMessage object
    ... CString strProp; ... CString outEntryID; ... I read somewhere about short term and long term entry IDs. ...
    (microsoft.public.win32.programmer.messaging)
  • Re: Delete History
    ... > How do I delete one entry from the address drop-down? ... depends on how long the entry has been in History. ... E.g. instead of just deleting a high-level node such as a site ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Move up text
    ... The usual syntax is rng1.Offset ... >I have the following code for deleting an entry on a worksheet:> ... > Set rng1 = rng ...
    (microsoft.public.excel.programming)
  • Re: [PHP] Securing AJAX requests with PHP?
    ... Thinking of man in the middle attacks they do not make much sense, ... If I'm deleting an entry from a database ... user won't like have that permission, the request will be logged and nothing ...
    (php.general)