Daqian said:
Hello,
for example,
int *temp = int[256];
I wont' use "temp" anymore, so how can I free it from memory? using free()
or delete temp; ? thx
In the above you have a syntax error.
The funny thing is, that using free() or delete [] depends
exactly on what you left out by prodicung that syntax error.
But from the rest of that line, one can conclude that in reality
that should read:
int* temp = new int[256];
Rule: new goes with delete
new [] goes with delete []
malloc goes with free
calloc goes with free
Since you have new [] in the above, the correct
memory release reads:
delete [] temp;
Usual post scriptum: Why don't you use std::vector? Much simpler
in the long run.
#include <vector>
int main()
{
std::vector temp(256);
// Look Ma. I don't have to worry about freeing the memory
// std::vector does all this by itself
}