Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1105363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:37:17+00:00 2026-05-17T01:37:17+00:00

I have digging through the C# code generated by SWIG for Quantlib and came

  • 0

I have digging through the C# code generated by SWIG for Quantlib and came across the following code that gave me a humbling moment.

Each of the generated classes implement IDisposable, and each of the generated classes have this convention pointed out below.

public class MultiPath : IDisposable { // MultiPath is interchangable
  private HandleRef swigCPtr;
  protected bool swigCMemOwn;

  internal MultiPath(IntPtr cPtr, bool cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = new HandleRef(this, cPtr);
  }

  internal static HandleRef getCPtr(MultiPath obj) {
    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  }

  ~MultiPath() { // <---- 
    Dispose();
  }

  public virtual void Dispose() {
    lock(this) {
      if (swigCPtr.Handle != IntPtr.Zero) {
        if (swigCMemOwn) {
          swigCMemOwn = false;
          NQuantLibcPINVOKE.delete_MultiPath(swigCPtr);
        }
        swigCPtr = new HandleRef(null, IntPtr.Zero);
      }
      GC.SuppressFinalize(this);
    }
  }
  // snip
}

If I’m reading this correctly, the bitwise complement operator is applied to the constructor of the class, so my questions are

  1. Why is the purpose of ~ operator in this example?
  2. What effect does it have?
  3. What are the correct situations to use such an operator and technique?

Edit:

Just for clarity, the ~ is this case is called a Destructor. Thanks’s @Arcturus.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:37:17+00:00Added an answer on May 17, 2026 at 1:37 am

    Its the destructor!

    In simple terms a destructor is a
    member that implements the actions
    required to destruct an instance of a
    class. The destructors enable the
    runtime system, to recover the heap
    space, to terminate file I/O that is
    associated with the removed class
    instance, or to perform both
    operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been digging through some ruby gem code and i came across these
These types of methods have always bothered me. Without digging through the code, I
I have just started digging into JavaFX and have a requirement that I am
I have found this macro while digging in the source code of tweejump game.
I'm looking at code that is new-to-me. I have c++ code in a project
While digging through some old code put together by a former co-worker who's talents
I have several large code bases which compile into dynamic libraries. I know that
I have done some digging out here and am still a little unsure how
I have been recently digging into Mobile Programming, I practically tried out the J2ME
While digging deeper into the latest release of F# I tried to have it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.