cin memory leak?

This is a discussion on cin memory leak? within the C++ Programming forums, part of the General Programming Boards category; I'm using a program (altnew.cc) that was provided by my class to measure the memory allocated. It's been working fine ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    186

    cin memory leak?

    I'm using a program (altnew.cc) that was provided by my class to measure the memory allocated. It's been working fine and I haven't been leaking any memory until I started changing how I read in input.

    Code:
    string input;
    cin >> input;
    I typed in a 'q' which exits my program and tells me the bytes allocated at the end. It should be 0 but theres 14 bytes allocated after cin which don't go away. Do I have to flush cin or something?

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by jcafaro10 View Post
    I'm using a program (altnew.cc) that was provided by my class to measure the memory allocated. It's been working fine and I haven't been leaking any memory until I started changing how I read in input.

    Code:
    string input;
    cin >> input;
    I typed in a 'q' which exits my program and tells me the bytes allocated at the end. It should be 0 but theres 14 bytes allocated after cin which don't go away. Do I have to flush cin or something?
    Probably your C++ runtime allocates some global data during setup of the standard streams. The runtime should theoretically free this data when it destructs itself, but, well... welcome to reality.

    Depending how you look at it, it's either a bug in the iostreams library, or it's harmless. I've seen this sort of thing so often I don't stop to worry about it.

    EDIT: I suppose it could be a bug in this altnew.cc module where it fails to account for some weird thing the iostreams library is doing. I'd give it 50/50% either way.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    cin cannot possibly deallocate its internally used data before any library-driven memory reporter runs. If the memory reporter can run, any other code can run too, and it might use cin. Bad if cin were to shut down before that.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting memory leak in complicating source code
    By mosxopul in forum C++ Programming
    Replies: 5
    Last Post: 03-30-2009, 11:41 AM
  2. memory leak in the code?
    By George2 in forum C++ Programming
    Replies: 20
    Last Post: 01-13-2008, 05:50 AM
  3. memory leak
    By rahulsk1947 in forum C Programming
    Replies: 2
    Last Post: 11-11-2007, 12:27 PM
  4. Is this code memory leak free? ---> POSIX Threads
    By avalanche333 in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2007, 03:19 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21