Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Been trying to figure this one out all day.
...
_HISTORY tempHist;
for(int i = 0; i < info.LogPerRecs; i++)
{
        CString msg;
        msg.Format("History #%d being allocated..",i);
	log.Write_Log_File(msg);
	tempHist = new History();
	msg.Format("New History allocated at %d",tempHist);
	log.Write_Log_File(msg);
...


Log says...
"
07/22/2010 13:39:56>History #20 being allocated..
07/22/2010 13:39:56>Beginning History Constructor
07/22/2010 13:39:56>Finishing History Constructor
07/22/2010 13:39:56>New History allocated at 13046208
07/22/2010 13:39:56>History #21 being allocated..
07/22/2010 13:39:56>Beginning History Constructor
07/22/2010 13:39:56>Finishing History Constructor
07/22/2010 13:39:56>New History allocated at 13046384
07/22/2010 13:39:56>History #22 being allocated..
"

And then it blows up with an error that says,
"The instruction at "0x7c911689" referenced memory at "0x00000000". The memory could not be "read""

Yet the only blob of code between my log statements is the dynamic allocation, and judging by the addresses of my previous allocations, I'm not exactly scraping the bottom of the barrel on addresses.

History class contains about 35 floats, nothing clever whatsoever inside of it, _HISTORY is a typedef for a pointer to said History class.

Code works fine in debug, has kittens in release. Any thoughts?
Posted

If you have only two classes (log writter, History) verify memory allocations/constructors and deallocations/destructors. You are propably incorrectly initializing/freeing a dynamically allocated block of memory.

Or publish these classes too.

You can also analyze minidump file (you will need .PDB files to do this).
 
Share this answer
 
v2
in each iteration of the loop you are allocating some memeory for History
tempHist = new History();
are you taking this memory and using somewhere in some other function?
if this memory is no longer used after each loop iteration, you can delete this at the end of each loop iteration.
otherwise it will go out of memory depending on number of loop iteration and size of History
code as below may help
...
_HISTORY tempHist;
for(int i = 0; i < info.LogPerRecs; i++)
{
        CString msg;
        msg.Format("History #%d being allocated..",i);
	log.Write_Log_File(msg);
	tempHist = new History();
	msg.Format("New History allocated at %d",tempHist);
	log.Write_Log_File(msg);
...
...
        delete tempHist;
        tempHist = 0;
}
 
Share this answer
 
Comments
Albert Holguin 9-Jun-11 1:29am    
although this is true, I doubt this would occur after 22 iterations unless History was huge...
Usually code that works fine in debug but doesn't work in release has a few problems:
1. Uninitialized variables- the debugger will auto-initialize all variables, but this is not the case in release mode, make sure all variables are properly initialized.
2. Array overflow- the debugger makes array allocations slightly bigger to facilitate debugging process (i.e. be able to find overflows without having the debug version crash), but again, release version does not do that.

Quick question, is this multi-threaded? ...that could further complicate things....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900