What are unmanaged objects?

What are unmanaged objects? Could you explain this in terms of the CLR? I found out on the Internet that they say that unmanaged objects do not run in the common language runtime. Could you give an example of unmanaged objects?

+4
source share
4 answers

Any memory that is not controlled by CLR memory management (i.e., the garbage collector) is unmanaged memory.

an OS file descriptor is one example of unmanaged memory (on .NET and Windows).

To get rid of unmanaged resources properly, it is recommended that you introduce the public to Dispose or close a method that executes the necessary cleanup code for the object. The IDisposable interface provides a Recycle method for resource classes that implement the interface. Because it is publicly available, an application can invoke the Dispose method directly to free memory used by unmanaged resources. When you correctly implement the Dispose method, the Finalize Method becomes a guarantee to clear resources in case the Dispose Method is not called.

Link: Clearing Unmanaged Resources

+7
source

In simple words, unmanaged objects are objects that are not controlled by the .Net framework.

Best example: a database connection or file operation is handled by the OS at the end and should be explicitly freed (File.Close () or Connection close) and will not be handled automatically by the garbage collector.

+5
source

Examples of VC ++ 6.0, or many of the ActiveX and COM objects that you use every day for your application or website, are unmanageable, such as Excel VBA unmanaged and too many other samples.

+2
source
I learned on the internet that they say unmanaged objects don't run under the CLR environment. 

That's wrong, the CLR is pretty much capable of doing everything possible inside C. In C #, you have a keyboard called unsafe that allows you to access even pointers and pointer offsets. I have a project where I make a heavy Interop with a game engine, and the C shell is so small that I can process all the memory objects in CLR / C #.

They do not start, they probably would like to explicitly indicate that virtual machines do not process uncommitted objects: you need to clean up or create wrapper classes that will clean you up.

+1
source

All Articles