In the unmanaged languages like C++ I can delete object using delete operator. But .NET platform is managed, so only the garbage collector can delete object from memory. We can only remove all references to the object and Garbage Collector will collect it sometime. But I want to perform instant delete of object.
Is there a way delete object using C++ library? The main idea:
- Create C++ library
- Define method
DeleteUnsafe(void* pointer)that usesmscoree.dllto delete object - Refer to the C++ library from .NET using
DllImportattribute
Is it possible to perform second step? Or use some another way to achieve my goal? What the start point?
Is it possible to perform without corrupting CLR? For example, GC will try collect already deleted object. How we can remove the object from GC queue?