I wrote the following method:
void ShowInfo::show_time(){
time_t rawtime;
struct tm *ti;
time ( &rawtime );
ti = localtime ( &rawtime );
std::cout << std::setw(2) << ti->tm_hour << ":"
<< std::setw(2) << ti->tm_min << ":"
<< std::setw(2) << ti->tm_sec;
}
Is it necessary to delete the struct ti to free memory, or it’s going to be deleted when the method ends?
And if it’s necessary to delete it, how do i do it?
You should check this with the documentation. A cursory search in google indicates that:
[http://en.cppreference.com/w/cpp/chrono/c/localtime]:
[http://msdn.microsoft.com/en-us/library/aa246456(v=vs.60).aspx]
So it seems that there is no dynamic allocation in place, and thus no need to release the memory back to the system.
More than the actual answer, you should understand that memory management is part of the interface of a function and must be documented. The docs are the simplest place to look for this information. Specially if you had to release the memory, the documentation would surely point this out.