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.
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?
cin >> input;
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.
Originally Posted by jcafaro10
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.
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.