Ok, Please, check the
Task Manager.
"Block code" in my opinion is the code which is only used to
debug (usually complex programs) that standard debug feature cannot.
Some functions which can do this effectively (which I'm currently using in many big projects) :
- Sleep();
- exit();
- ExitProcess();
- MessageBox();
- FatalAppExit();
- sprintf, printf
1 2 3
|
int *var;
*var = 10; //Crash!
|
1 2 3 4
|
int *var;
MessageBox(0,"Hahahaha","Hihihi",0);
*var = 10;
MessageBox(0,"HoHoHoHo","Hihihi",0); //"Hohohoho" is never reached -> The problem here - *var = 10;
|
About your memory leak : You also can use this to watch your program progress (with your
Task Manager) A very simple example :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
void SetValue(double *var, double value)
{
var = new double(); //Suppose you forgot to free "var"
*var = value;
}
int main()
{
double *a, b, c;
b = 10;
c = 15;
for(int i = 0;i < 10000000;i++)
{
SetValue(a, i);
b = pow(*a, 2);
c = pow(b, 2);
}
return 0;
}
|
Certainly It causes memory leak.
Now, you put some block code, for example :
1 2 3 4 5 6 7
|
for(int i = 0;i < 10000000;i++)
{
SetValue(a, i);b = pow(*a, 2);c = pow(b, 2);
Sleep(1); //Sleep block command
}
MessageBox(0,"Done.","!!!",0); //MessageBox block command
|
Now you open up the
Task Manager and see the program memory-consuming grows up and up. Test it, and you will see.
Another example :
1 2 3
|
Sleep(5000);
function([...]); //which is very questionable
MessageBox(0,"Done.","!!!",0);
|
Open the
Task Manager, the open your program, wait for 5 seconds. Look at your program process and find information
"Memory Usage". Watch it closely. Then you'll see
memory leak. :)
Then you basically detected the problem. Expand the code and continue putting the block code (where you doubt). Many fatal errors or (memory leak) errors can be avoided. :)