memory leak w/out variable allocation

I keep getting a huge memory leak with the g++ compiler (v. 4.4.1), as can be seen from the command "top" which shows "used" memory on my 16GB machine running Ubuntu.
I never use the constructors or destructors (new, or delete). I am, however, dealing with a very large input file (6.6GBs).

I'm still quite a beginner with programming in c++, but after much google searching, I do not understand why this is happening?

Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

int main()
{

  ifstream DATAIN;
  ofstream DATAOUT;
  int i=0;
  string sPass;
  string sString;


  


  DATAOUT.open("part_001.dat");
  DATAIN.open("GPL6947_family.soft");
  while(  getline(DATAIN,sString)  ){
    if(sString == "!Sample_series_id = GSE22070"){
      sPass=sString;
      break;
    }
    DATAOUT << sString <<endl;
  }
  DATAOUT.close();



  DATAOUT.open("part_002.dat");
  DATAOUT << sPass <<endl;
  while(  getline(DATAIN,sString)  ){
    DATAOUT << sString <<endl;
  }
  DATAOUT.close();
  DATAIN.close();





  return 0;
}



That program has no memory leak
I agree with that logic. Ok, thanks for the reply. I suppose this has to do with my operating system then?

Thanks for the reply.
The overall "Used" field may not be the best indicator of per-process usage.

What does top show for your actual process under "RES" and "%MEM" columns?
Last edited on
closed account (1yR4jE8b)
Since you're on Ubuntu, you can install "valgrind" to check your program for errors.
Not that there's anything wrong with what you're doing, but wouldn't a task like that be much quicker with shell?

Use grep -n to find the appropriate line number you want to split on, and then head and tail to get the separate parts.
thanks for all the replies.

@Cubbi: I'm running another program that will take a while to finish, but I will look into what the different fields mean, since, I believe, you are implying "Used" is not exactly used.

@darkestfright: I had read about that, but what I was doing was so simple, I just didn't understand how I was getting a "leak."

@kev82: OMG, how I love Linux. I know about all the commands you mentioned, but never thought about putting them together. My perl program blew up, so I thought I would use c++ to split the file. Thanks again kev82!

Thanks guys!

-Ben
Topic archived. No new replies allowed.