How to Force a Destructor Call in C++ Net

The .Net Framework has an extensive memory management system that cleans up old, unused segments of memory periodically. This process is usually referred to as "garbage collection." Most programs can just let the garbage collection process work automatically in the background. However, some programs need to perform their own garbage collection. This is particularly true when a .Net program interfaces with an unmanaged resource. An unmanaged resource is one that is foreign to the .Net framework. One way of disposing of an unmanaged resource is to call its destructor directly using C++.

Things You'll Need

  • Visual Studio Integrated Development Environment (IDE)
  • .Net Framework 4.0 or later
Show More

Instructions

    • 1

      Open the Visual Studio IDE and make a new C++ project. A blank source code file will appear on the main workspace window.

    • 2

      Create a new String object by typing the following line of code:

      String myString = new String();

    • 3

      Call the destructor by typing the following line of code:

      myString.String::~String();

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured