Program crashes with "delete"

Here's my function:

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
	Note *temp;
	level_elapsed_time = timeGetTime() - level_start_time;
 
	for(int i = 0; i < 18; ++i)
	{
		bool disposeNote = false;
		for(int j =0; j < notes[i].size(); ++j)
		{
			temp = notes[i].at(j);
			bool next = false;
			if(temp->getSpawnTime() <= level_elapsed_time)	
			{
				temp->updateYPos();
				
				if (j == 0)
				{
					if(temp->getYPos() < 335)
					{
						if(GetAsyncKeyState(keyConstants[i]))
						{
							combo = 0;
						}

					}

					else if(temp->getYPos() >= 335 && temp->getYPos() <= 365)
					{
						if(GetAsyncKeyState(keyConstants[i]))
						{
							disposeNote = true;
							combo += 1;
						}

					}
					else
					{
						disposeNote = true;
						combo = 0;
					}
				}

				if(disposeNote)
				{
					delete temp;
					notes[i].erase(notes[i].begin());
				}
				
			}
			else
			{
				break;
			}
		}

	}
}


when i insert delete temp right before the function ends, my program crashes. Without that extra line, the program works fine but lags after some time.

What's wrong in there?
Put simply, you can only delete what you new. There is no new in this code, so why would there be a delete?
Oh thanks! Im new to c++ an I'm wondering if there are any memory leaks in that part of the code?? Thanks!
Unless one of the functions you've written that gets called above uses a new somewhere, there are no memory leaks.
Thanks a lot! One more thing though, my program slows down a bit after about 15 seconds of running, aside from memory leaks, are there any possible reason why the program slows down??
Topic archived. No new replies allowed.