Hi would like some explanation about the delete command. ok I need to use it if I want to delete an objekt which is dynamic allocated during the run of the program, but do I need t o write an implemenatition and how should it look?
Also I'd like to know if c++ free all the dynamic allocated memory when the program terminates. Or if i've written a program which allocates memory dynamic and then trerminates the program without have made any destructors in my classes if the memory doesn't free up. sry 'bout d english
delete is using to free memory allocated with new. You must use it before the program is terminated, otherwise the memory will not be freed (and you will have a memory leak).
so if I don't include a destructor in my class definition I will have a memory leak? Is there somehow I can free up memory beeing used after the program has terminated? or do I need to buy a new DDR2?
so how do I implement a destruktor. I know that you declare it
Class A{
public:
~A();
};
correct? but how shoul the definition file be like?
You have a memory leak if you allocate something with 'new' and don't free it with 'delete'. It has nothing to do with having a class destructor (although destructors are commonly used to ensure you delete everything you've allocated).
I'm skeptical as to whether or not the memory remains "leaked" after the program is terminated. I'm pretty sure any modern OS will free leaked memory by a program once it closes -- although you shouldn't rely on this as it might not always be the case.
In any event, you don't need to buy new RAM. At worst all memory will be restored if you reboot.