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

  • SEARCH
  • Home
  • 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 3623618
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:24:21+00:00 2026-05-18T23:24:21+00:00

Consider the following example F# code: type mytype() = member this.v = new OtherClass()

  • 0

Consider the following example F# code:

type mytype() =
   member this.v = new OtherClass()

If OtherClass implements IDisposable, does the member binding act like a let binding or a use binding? Is there any way to get it to act as a use binding? I have some code very similar to this and I want to insure that the Dispose is called when the parent object goes out of scope.

A quick scan through Expert F# failed to turn up anything definite but perhaps I am looking for the wrong terms in the book.

  • 1 1 Answer
  • 0 Views
  • 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-18T23:24:22+00:00Added an answer on May 18, 2026 at 11:24 pm

    In your snippet, the body of the member v will be evaluated each time the member is called (meaning that it will create a new instance of OtherClass each time someone uses it). The member simply returns the newly created object and you could use it like this:

    let m = new MyType()
    use v = m.V // 'use' binding
    

    I’m not sure if this is what you were asking though. If you want to create only a single instance, you’ll need to write something like this:

    type MyType() =
      let v = new OtherClass() 
      member this.V = v
    

    This behaves as usual let binding and the v value won’t be disposed automatically when the current instance of MyType is disposed. To have v automatically disposed, you’ll need to implement IDisposable in MyType explicitly:

    type MyType() =
      let v = new OtherClass() 
      member this.V = v
      interface IDisposable with 
        member x.Dispose() = (v :> IDisposable).Dispose()
    

    Unfortunately, there is no syntactic sugar that would make it nicer (I once suggested allowing use and implicitly implementing IDisposable for type members to the F# team, but they didn’t implement it
    (yet:-))).

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

Sidebar

Related Questions

No related questions found

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.