Click here to Skip to main content
15,891,725 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Use of extern Pin
sweep12328-Jun-04 22:33
sweep12328-Jun-04 22:33 
GeneralRe: Use of extern Pin
Xzyx987X28-Jun-04 23:01
Xzyx987X28-Jun-04 23:01 
GeneralRe: Use of extern Pin
sweep12328-Jun-04 23:22
sweep12328-Jun-04 23:22 
GeneralRe: Use of extern Pin
Rick York29-Jun-04 6:16
mveRick York29-Jun-04 6:16 
GeneralRe: Use of extern Pin
Johnny ²29-Jun-04 4:48
Johnny ²29-Jun-04 4:48 
GeneralAnimateWindow() Question Pin
User 58385228-Jun-04 21:37
User 58385228-Jun-04 21:37 
GeneralSetting up Visual C++ .NET to break on a windows error Pin
Xzyx987X28-Jun-04 20:48
Xzyx987X28-Jun-04 20:48 
QuestionWay to Prevent memeory leak? Pin
nachilau28-Jun-04 20:29
nachilau28-Jun-04 20:29 
Hello all,

I have a question on about how to prevent to prevent the memory leak? I am writing a window program, and I have an Assert() so that if any fatal erorr occured, the Assert() will call
Sleep(INFIITE) to stop the program, and print out the error message to the user. By doing that, the only way to exit the program after Assert() has been called is to close the window. However, it causes a problem which is that even though the desturctor of each classes in the program will be called when the user close the window, there may still some memory leak in the local scoop when I use Assert() like this, eg in funciton f()

f() {
char* name = new char[10];
Assert(AnyError(), "Fatal Error!");
strcpy(name, "Hello");
delete [] name;
}

For example, if I get the Assert() if I get any error in f(), then when the user close the window, I will have a memory leak for 10 bytes. What is the best way to solve the problem? I don't want to use the try and catch block since the code will be mess up with all those try and catch block. And I really want to stop the program when the fatal error occurs. Any ideas? Thanks!



Nacho
AnswerRe: Way to Prevent memeory leak? Pin
User 58385228-Jun-04 20:43
User 58385228-Jun-04 20:43 
GeneralRe: Way to Prevent memeory leak? Pin
nachilau28-Jun-04 21:09
nachilau28-Jun-04 21:09 
GeneralRe: Way to Prevent memeory leak? Pin
User 58385228-Jun-04 21:34
User 58385228-Jun-04 21:34 
AnswerRe: Way to Prevent memeory leak? Pin
wb28-Jun-04 21:42
wb28-Jun-04 21:42 
GeneralRe: Way to Prevent memeory leak? Pin
nachilau28-Jun-04 21:51
nachilau28-Jun-04 21:51 
GeneralRe: Way to Prevent memeory leak? Pin
wb28-Jun-04 22:05
wb28-Jun-04 22:05 
GeneralSerial Communication in WIN CE Pin
Chinnaa Ganesh Kumar28-Jun-04 20:07
Chinnaa Ganesh Kumar28-Jun-04 20:07 
Generalstd::queue and Managed class Pin
Vadim Tabakman28-Jun-04 19:54
Vadim Tabakman28-Jun-04 19:54 
GeneralRe: std::queue and Managed class Pin
Nemanja Trifunovic29-Jun-04 7:23
Nemanja Trifunovic29-Jun-04 7:23 
GeneralRe: std::queue and Managed class Pin
Vadim Tabakman29-Jun-04 13:36
Vadim Tabakman29-Jun-04 13:36 
GeneralQuestion on prefix and post fix Pin
rohit.dhamija28-Jun-04 19:49
rohit.dhamija28-Jun-04 19:49 
GeneralRe: Question on prefix and post fix Pin
PJ Arends28-Jun-04 19:57
professionalPJ Arends28-Jun-04 19:57 
GeneralRe: Question on prefix and post fix Pin
Ian Darling29-Jun-04 2:57
Ian Darling29-Jun-04 2:57 
GeneralRe: Question on prefix and post fix Pin
Vadim Tabakman28-Jun-04 19:58
Vadim Tabakman28-Jun-04 19:58 
GeneralRe: Question on prefix and post fix Pin
rohit.dhamija28-Jun-04 20:14
rohit.dhamija28-Jun-04 20:14 
GeneralRe: Question on prefix and post fix Pin
Vadim Tabakman28-Jun-04 20:28
Vadim Tabakman28-Jun-04 20:28 
GeneralSOAP 3.0 Question Pin
NeoHobbit28-Jun-04 19:28
NeoHobbit28-Jun-04 19:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.