deallocate memory

Hello everyone, I have two dynamic arrays at the end of the cycle, I must deallocate the memory.
Can you tell me where I'm wrong.
1
2
3
4
5
6
7
8
9
10
11
12
...code
for(;nline>0;nline--){
		int * array = new int[n];
		for(int j=0;j<n;j++) array[j] = 0;
		
		int * count = new int[(n+1)];
		for(int j=0;j<n+1;j++) count[j] = 0;
	
		delete [] array; /*or delete array;*/
		delete [] count;  /*or delete count;*/
	}


I returned the following error:
terminate called after throwing an instance of std bad_alloc
the problem seems to be in the allocation. Not sure what may be wrong beyond that. Perhaps heap corruption? Or check that n is not unreasonably big (like, try and allocate 4 gigs of memory).
Last edited on
Topic archived. No new replies allowed.