using "new"

Hi, I have a question regarding dynamic memory allocation using "new".

1
2
3
4
MyDataType* obj;
obj = new MyDataType[3];

obj = new MyDataType[10];



In the upper example I am little bit confused. Does the carbage collector takes care of it the first "new"?

I know that it is valid, and I can not use Delete between these to "new"s.


Adv. thanks,

//kursist
closed account (z05DSL3A)
Pure C++
There is no garbage collection, so you would need to do:
1
2
3
4
MyDataType* obj;
obj = new MyDataType[3];
delete[] obj;
obj = new MyDataType[10];


Managed extensions for C++ (MC++) (.net: old)
I think it depends on how MyDataType is defined.

C++/CLI (.net: new)
As it was created with new, it should be deleted. If it were a managed class it should be gcnewed, then garbage collection should clean it up.
Thanks for reply,
Topic archived. No new replies allowed.