|
-
December 12th, 2002, 10:14 AM
#1
life span of dynamicaly allocated memory
Hi Guys,
Cinsider the code:
class MyClass { /*stuff*/};
void foo()
{
MyCalss variable;
Myclass *pointer = new MyClass;
/* do stuff */
}
Which of the following is correct:
1.At the end of the function scope, both, variable and pointer will be destryed, that includes automatic destructor call for pointer, and all memory use by both variable and pointer will be returned to the system
2.At the end of the function scope, Only variables memmory is returned to the system, while only the pointer it self is destroyed but the allocated memory stays, untill delete will be called for it explicitly.
I think 2 is correct - can any one second that?
If its true, it actualy means, that dynamic allocation is in fact static - since the momory stayes "reserved" untill explicit delete call.
I use to think all "things" that are not declared as "static" should be dedstryed on end of scope - including the memory they used...
Thanks for any replies.
All the best
Dani.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|