|
From: Daniel G. <sp...@ho...> - 2003-03-01 15:19:58
|
For C++ you must delete any objects you create with the new operator.
Variables created normally will be destroyed when they go out of scope.
So
int main(int argc, char** argv)
{
int SomeInt = 0;
return 0;
}
// SomeInt has been destroyed.
or try
int main(int argc, char** argv)
{
{
// The { doesn;t do anything except limit
// the scope of everything within.
int SomeInt = 0;
} // someInt now destroyed.
return 0;
}
but if you do
MyClass* Ptr; // Ptr can point to a MyClass object
Ptr = new Myclass;
//...
delete Ptr; // Delete the object and free the memory.
This is because with 'new' you allocate memory at run time, not at compile
time.
>From: "Robson Bernard" <rob...@su...>
>To: "C++ Mail List" <dev...@li...>
>Subject: [Dev-C++] Memory
>Date: Sat, 1 Mar 2003 11:47:26 -0300
>
>Hi coders,
>
>I have a question that does not want to shut up! When i code a program, do
>i
>have to delete all variables before exiting the main function or does the
>operating system cares of free all the memory allocated? If i do not delete
>the variables before main function and use the program several times, may
>it
>cause the system memory to be unavailble?
>
>Any input welcome!
>
>Thanks!
>
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://messenger.msn.co.uk
|