Memory Leak Issues?

I'm not expecting anyone to spend a lot of time, but I am running my program through something that detects memory leaks and am getting back that I am leaking a lot of memory. I can't figure out where or how or what to do to fix it.

Could someone give some tips for detecting and fixing memory leaks and / or possibly give my code a quick glance and just see if there are any obvious places it might be leaking memory. Any advice would help!

Thanks,
Travis
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
int main() {
//main arrays
Table *tables[100];
int tableCount=0;

//Waiter vars
Waiter waiters[100];
int numWtrs = 0; //Number of waiters so far
string waiterName;
string wtrTables;

//Menu and MenuItem vars
Menu myMenu = Menu();
string code;
string name;
double price;
Order *myOrder;
int count;
int value; //
string token;
Tokenizer str;

///////////////////////////////////////////////////////////////
////////////////////////CONFIGURATION///////////////////////////
string line;
ifstream config("config.txt");

if(config.is_open())
{
	while(!config.eof()) {
		getline (config,line);
		///////////////////DETERMINE WHAT WE ARE READING
		int headerType;//0 for Tables, 1 for Waiters, 2 for Menu, -1 for blank line
		stringstream lineType(stringstream::in|stringstream::out);
		lineType<<line;
		string header;
		lineType>>header;
		if(header=="Tables:"||header=="Waiters:"||header=="Menu:"||header=="") {
			if(header=="Tables:")
				headerType=0;
			else if(header=="Waiters:")
				headerType=1;
			else if(header=="Menu:")
				headerType=2;
			else //read in empty line
				headerType=-1;
		}
		////////////////////READ INPUT BASED ON TYPE
		else { 
			stringstream setup(stringstream::in|stringstream::out);
			setup<<line;
			switch(headerType) {
				case 0: //Table
				
					//Input vars
					int tableID;
					int maxSeats;
					
					//read vars
					setup>>tableID;
					setup>>maxSeats;
					
					//Create a new table and put into object array
					tables[tableID]=new Table(tableID,maxSeats);
					tableCount++;
					break;
				case 1: //Waiters
				
				//Read 
				setup>>waiterName;
				setup>>wtrTables;
				
				//Place new object in array
				waiters[numWtrs] = Waiter(waiterName,wtrTables);
				
			str=Tokenizer(wtrTables);
		 	str.setDelimiter(",");
			 while ((token = str.next()) != "") {
		 	value = atoi(token.c_str());
		 	
		 	(*tables[value]).assignWaiter(&waiters[numWtrs]); 
		}
				numWtrs++;
				break;
				case 2: //Menu
				
				//Read in vars
				setup>>code;
				setup>>name;
				setup>>price;
				
				//Add to Menu Object
				myMenu.addItem(MenuItem(code,name,price));
				
				break;
			}
		}//else statement - means recording config non header lines
	}
}
config.close();

///////////////////////////////////////////////////////////////
////////////////////////ACTIVITY///////////////////////////
ifstream activity("activity.txt");
int totalOrders=0;
if(activity.is_open()) {
	while(!activity.eof())
	{
		getline(activity,line);
		
		//Tokenize to get different tokens
		//All commands start with T# with # refering to table number
		Tokenizer act(line);
		act.setDelimiter(" ");
		string actTemp = act.next();
		int tableNum = actTemp[1]-48; //convert char to int of table #
		
		//Now find the command
		actTemp = act.next();
		char cmd = actTemp[0];
		
		switch(cmd) {
			case 'P': //Assign party to a table
			//Check if waiter has been assigned or if party has been assigned
			if((*tables[tableNum]).hasWaiter()==1&&(*tables[tableNum]).hasParty()==0)
				(*tables[tableNum]).partySeated((actTemp[1]-48)); //Assign a party to the table
			break;
			case 'O':
				free(myOrder);
				myOrder=new Order(100);
				actTemp = act.next();
				count = 0;
				while(actTemp!="") {
					(*myOrder).addItem(myMenu.findItem(actTemp.substr(0,2)));
					count++;
					actTemp=act.next();
				}
				(*tables[tableNum]).partyOrdered(myOrder);
				totalOrders++;
			break;
			case 'S':
				(*tables[tableNum]).partyServed();
			break;
			case 'C':
				(*tables[tableNum]).partyCheckout();
			break;
		}
		
	}
	
}
activity.close();

///////////////////////////////////////////////////////////////
////////////////////////QUERIES///////////////////////////
int query=0;
int counts;
int tableChoice;
while(query!=6) {
	cout<<"1. How many tables are occupied right now?"<<endl;
	cout<<"2. How many open orders right now?"<<endl;
	cout<<"3. How many orders have been processed so far?"<<endl;
	cout<<"4. What is the average occupancy of particular table today?"<<endl;
	cout<<"5. What are the top 3 popular entries today?"<<endl;
	cout<<"6. Exit Queries"<<endl;
	cout<<"Enter your query command: ";
	cin>>query;
	
	switch(query) {
		case 1: //occupied tables
			counts=0;
			for(int i=1;i<=tableCount;i++) {
				if((*tables[i]).hasParty()==1)
					counts++;
			}
			cout<<endl;
			cout<<"There are "<<counts<<" occupied tables."<<endl;
			cout<<endl;
		break;
		case 2: //open orders
					counts=0;
			for(int i=1;i<=tableCount;i++) {
				if((*tables[i]).openOrder()==1)
					counts++;
			}
			cout<<endl;
			cout<<"There are "<<counts<<" open orders."<<endl;
			cout<<endl;
		break;
		case 3: //processed orders
							counts=0;
			for(int i=1;i<=tableCount;i++) {
				if((*tables[i]).openOrder()==1)
					counts++;
			}
			cout<<endl;
			cout<<"There were "<<(totalOrders-counts)<<" processed orders."<<endl;
			cout<<endl;
		break;
		case 4: //Avg occupancy of table
		//Total number of people seated at table
		//Divided by total number of parties seated at the table
		cout<<"Enter a table for your query: ";
		cin>>tableChoice;
		if(tableChoice>0&&tableChoice<=tableCount)
			{cout<<"Average occupancy: "<<((*tables[tableChoice]).avgOccup())<<" people"<<endl;}
		else
		cout<<"Table number not valid."<<endl;
		break;
		case 5: //Top 3 popular entries
		myMenu.top3();
		break;
	}
}
	return 0;
}

A simple search shows your program uses the new keyword twice, but it never calls delete on the objects created with new.
Topic archived. No new replies allowed.