473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

memory leak with a thrown exception

hello; does anybody know why i'd get a memory loss at this point?

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3.  
  4.  
  5. int main(int argc, char *argv[]){
  6. try {
  7. throw 1;
  8. }
  9. catch(int) {
  10. cout<<"Catch\n";
  11. }
  12. return EXIT_SUCCESS;
  13. }
  14.  
  15.  
Nov 7 '06 #1
10 1582
* rupert:
hello; does anybody know why i'd get a memory loss at this point?
It happens to everybody. Just be honest about it.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. int main(int argc, char *argv[]){
  3.     try {
  4.        throw 1;
  5.     }
  6.     catch(int) {
  7.        cout<<"Catch\n";
Expand|Select|Wrap|Line Numbers
  1.  
  2. Should not compile, should be
  3.  
  4. std::cout << "Catch\n";
  5.  
  6. To ensure that that output appears it would also be a good idea to do
  7.  
  8. std::cout << std::flush;
  9.  
  10. Which you can combine with the above by doing
  11.  
  12. std::cout << "Catch" << std::endl;
  13.  
  14.  
  15.         
  16.                     }
  17.     return EXIT_SUCCESS;
  18.  
  19. This constant is not guaranteed to be available by including <iostream>.
  20.  
  21.  
  22.         
  23.                 }
  24.  
  25.  

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 7 '06 #2
Sorry correction;

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <map>
  3. #include <iostream>
  4.  
  5. using std::cout;
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. try
  10. {
  11. throw 1;
  12. }
  13. catch(int)
  14. {
  15. cout<<"Catch\n";
  16. //std::flush;
  17. }
  18. return 0;
  19. }
  20.  
  21.  
sorry try again. seems even with std::flush i still get a memory leak

Nov 7 '06 #3
* rupert:
Sorry correction;

Expand|Select|Wrap|Line Numbers
  1. #include <map>
  2. #include <iostream>
  3. using std::cout;
  4. int main(int argc, char *argv[])
  5. {
  6.     try
  7.     {
  8.        throw 1;
  9.     }
  10.     catch(int)
  11.     {
  12.       cout<<"Catch\n";
  13.      //std::flush;
  14.     }
  15.     return 0;
  16. }
  17.  

sorry try again. seems even with std::flush i still get a memory leak
It's unclear what you mean by "memory leak".

Do you mean that no output appears?

Try running the program from the command line (if you haven't).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 7 '06 #4
Oh the program compiles and runs. however bcheck ./myProg displays one
occurance of a memory leak. and can't figure out why; when there's no
initialization of any "new" things nor pointers to dynamically
allocated objects, simply a "throw" confusing eh?....

Nov 8 '06 #5

Alf P. Steinbach wrote in message <4r************@mid.individual.net>...
>* rupert:
>Sorry correction;
Expand|Select|Wrap|Line Numbers
  1. #include <map>
  2. #include <iostream>
  3. using std::cout;
  4. int main(int argc, char *argv[]){
  5.     try{
  6.        throw 1;
  7.        }
  8.     catch(int){
  9.       cout<<"Catch\n";
  10.      //std::flush;
Expand|Select|Wrap|Line Numbers
  1.  
  2. OP: That should be 'std::cout<<std::flush;'.
  3.  
  4.         
  5.                         
  6.                 >    }
  7.     return 0;
  8. }
  9.  
  10.  
>>
sorry try again. seems even with std::flush i still get a memory leak

It's unclear what you mean by "memory leak".
Fool, Alf! (<G>) Can't you see, it's right in front of you. He said, " **i**
still get a memory leak" [1]. Didn't say anything about the program!
(....or the std::map use.)

[1] - I get that all the time with CRS and Sometimers disease! (....in fact,
I think it's happening right now!)
--
Bob <GR
POVrookie
Nov 8 '06 #6

rupert wrote in message
<11**********************@m73g2000cwd.googlegroups .com>...
>Oh the program compiles and runs. however bcheck ./myProg displays one
occurance of a memory leak. and can't figure out why; when there's no
initialization of any "new" things nor pointers to dynamically
allocated objects, simply a "throw" confusing eh?....
May be a false positive. As soon as you throw, it exits the try{}
(immediately, does not finish it), and starts looking for a handler. Maybe
'bcheck' is keying off the missing closing brace (due to the throw).

Is there anything else in main()?

--
Bob R
POVrookie
Nov 8 '06 #7
Easy bob, my question to was unclear to Alf, who's the only person
helping me at the moment. It will teach me to be ask better questions.

Nov 8 '06 #8
Is there anything else in main()?
no that's it.

Nov 8 '06 #9
On 7 Nov 2006 19:20:11 -0800, "rupert" wrote:
>Oh the program compiles and runs. however bcheck ./myProg displays one
occurance of a memory leak. and can't figure out why; when there's no
initialization of any "new" things nor pointers to dynamically
allocated objects, simply a "throw" confusing eh?....
The leak probably stems from iostreams. Try to leave out cout (don't
#include <iostream>).

Best wishes,
Roland Pibinger
Nov 8 '06 #10
VJ
rupert wrote:
Sorry correction;

Expand|Select|Wrap|Line Numbers
  1. #include <map>
  2. #include <iostream>
  3. using std::cout;
  4. int main(int argc, char *argv[])
  5. {
  6.     try
  7.     {
  8.        throw 1;
  9.     }
  10.     catch(int)
  11.     {
  12.       cout<<"Catch\n";
  13.      //std::flush;
  14.     }
  15.     return 0;
  16. }
  17.  

sorry try again. seems even with std::flush i still get a memory leak

It might be a false report in your memory leak check program. I
encountered such using valgrind in various cases (one case was a memory
leak report when an exception throws)
Nov 8 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chris Martin | last post by:
Below are three try-catch blocks. My question is, how can all three work, and how come there is no memory leak (or is there)? As I understand it, an exception object is being created and "thrown"...
6
by: Fred Zwarts | last post by:
Hello, I am trying to debug some complex debug code. In order to track the use of dynamically allocated memory, I replaced the standard global new and delete operators. (Not for changing the...
1
by: bw | last post by:
I have a basic custom collection that throws a new exception if the item(key) is not found in the collection. This is used as part of a calling function. It all works correctly, the problem...
12
by: Grahamo | last post by:
Hey, this is related to absolutely nothing in particular and is of no importance whatsoever except for my curiousity. Does anybody have an example of a particularly tricky memory leak that's...
4
by: =?gb2312?B?uqO35w==?= | last post by:
Hi i am using libMagick++.a of Magick-6.2.8 in linux.but now i encounter some leaks when reading blob into image , writting image into blob, or throwing expection .that are my code patch and...
4
by: O.B. | last post by:
I've got this C# .NET 2005 application that has some unmanaged code. At random times, I get: An unhandled expection of type 'System.AccessViolationException' occurred in Unknown Module. ...
27
by: George2 | last post by:
Hello everyone, Should I delete memory pointed by pointer a if there is bad_alloc when allocating memory in memory pointed by pointer b? I am not sure whether there will be memory leak if I do...
2
by: =?Utf-8?B?Tm9tYW4gQWxp?= | last post by:
Hi, We are facing a strange problem in our ASP. NET website. Some times it gives the following unhandled exception. Error Message: Exception of type System.Web.HttpUnhandledException was...
13
by: Pep | last post by:
I have recently eradicated a lot of memory leaks in a very old C++ source set. However, whilst they were all fairly easy to resolve, I am confused by the last one. This seems to be related to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.