Quote:Original post by owl
I don't see the problem if the program is going to exit anyway. To be a leak, the program should still be running.
I agree. Although, it is a good practice for several reasons to clean up before we exit, rather than hoping the OS will do the job for us (some reasons: OS bugs, forgetting to delete critical buffers may imply we're also forgetting to save it's content to disk, etc)
How about this?:
[source=cpp]void MyExit( list<int> &l ){ l.clear(); exit(0);}int main(){ list<int> list1(100, 123); // Create a list with 100 ints with value 123. MyExit( list1 );}
Not the finest solution, but it's something. Why do you want to use/need exit() anyway?
I haven't ever used it in my development years. Try thinking in a better design that avoids using it.
And if you're planning to use it for emergencies (i.e. crashes) it is fine to cause memory leaks, as often crashes are some memory pointers are corrupted, invalid or overflowed, in which case you wouldn't be able to free anyway.
Also take note that this code:
[source=cpp]void MyMain(){ list<int> list1(100, 123); // Create a list with 100 ints with value 123.}int main(){ MyMain(); exit(0);}
will work since list1 is in MyMain's stack, not in main()
Hope this helps
Dark Sylinc