Greenhorn
Greenhorn

Reputation: 668

What are Managed objects and unmanaged objects in C++/CLI?

What are Managed objects and unmanaged object in C++/CLI

Upvotes: 1

Views: 2213

Answers (3)

user2100815
user2100815

Reputation:

Managed objects are a feature of the .NET framework and its implementation of a C++-like language, and have their memory managed for you by the .NET garbage collector. C++ itself has no such concept, and a better (in general) way of managing all resources (not just memory) called RAII.

Upvotes: 5

Patrick
Patrick

Reputation: 23619

The concept Managed/Unmanaged is not typically C++. It is Microsoft .Net technology speak.

In normal, plain C++ applications, the application itself is responsible for deleting all the memory it has allocated. This requires the developer to be very careful about when to delete memory. If memory is deleted too soon, the application may crash if it still has a pointer to it. If memory is deleted too late, or not deleted at all, the application has a memory leak.

Environments like Java and .Net solve this problem by using garbage collectors. The developer should not delete memory anymore, the garbage collector will do this for him.

In the 'native' .Net languages (like C#), the whole language works with the garbage collector concept. To make the transition from normal, plain C++ applications to .Net easier, Microsoft added some extensions to its C++ compiler, so that C++ developers could already benefit from the advantages of .Net.

Whenever you use normal, plain C++, Microsoft talks about unmanaged, or native C++. If you use the .Net extensions in C++, Microsoft talks about managed C++. If your application contains both, you have a mixed-mode application.

Upvotes: 4

user541686
user541686

Reputation: 210402

Managed objects do not exist in C++.

They exist in Microsoft's .NET extensions to C++, and a complete explanation would be a bit long, sorry.

Upvotes: 0

Related Questions