Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VS2008 C++
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 22-Jul-10 10:50am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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).
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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;
}
  Permalink  
Comments
Albert Holguin at 9-Jun-11 1:29am
   
although this is true, I doubt this would occur after 22 iterations unless History was huge...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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....
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 265
2 Praneet Nadkar 237
3 Marcin Kozub 225
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 9 Jun 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100