Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

memory could not be read

Status
Not open for further replies.

AliAndAli

Programmer
Aug 3, 2002
27
0
0
US
I have a VC++ 6.0 program on Windows 2000. I run my program in the debugger and it works fine. But when I start it by double clicking on its icon, after sometime I get an error message:

The instruction at "0x0042b1b5" referenced the memory at "0xcdcdcdcd". The memory could not be read.

This is not a consistent behavior, but the address "0xcdcdcdcd" is always the same. The crash happens very frequently. I know in the debug mode, Microsoft initializes non initialized pointers to "0xcccccccc". The address "0xcdcdcdcd" in the message does not seem like a random address. Any body has seen something like this before? Is there anything particular about this address?

The error message has the usual press OK to stop the progam or Cancel to debug, but pressing Cancel causes the process to exit and does not bring up the debugger.
 
You might be trying to assign or delete memory that was not allocated. Or you might be failing to release memory that was allocated.

This happens when you use "delete" on an object that was never created with "new".

See if you have a "new" for every "delete" in your code.

Also if you have an array that was allocated with new, check to make sure you have not gone over its boundaries.

Also check that you have allocated or deleted your type correctly. For example, when you allocate:

myVar = new double[100];

you must use:

delete [] myVar;

when you delete.

Post some code and we can help you out better, especially code where you are allocating or freeing dynamic memory.

The reason the error does not occur in debug mode is that memory is handled differently there, it's safer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top