Maybe you should implement IDisposable and override Finalize() ?

By on 8/6/2008 12:24 PM ()

Hi,

perhaps Julian is referring to disposal of the member objects of a class instance?

attempting to use implicit class constructors with use bindings causes the following error:

1
2
3
type ParentClass() =

    use child = new ChildClass()

Warning FS0191: 'use' bindings are not permitted in implicit class constructors. file1.fs

using a let binding, however, doesn't call the Dispose function in child objects.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#light

module DisposalTest 

open System

type ChildClass() =
    do printfn "creating object of class ChildClass"
    interface IDisposable with
        member x.Dispose() = printfn "disposed object of class ChildClass"

type ParentClass() =
    let child = new ChildClass()
    do printfn "creating object of class ParentClass"
    interface IDisposable with
        member x.Dispose() = printfn "disposed object of class ParentClass"
        
let main() =
    use parent = new ParentClass()
    ()
    
do main()        

produces the following output

>project1.exe
creating object of class ChildClass
creating object of class ParentClass
disposed object of class ParentClass

notice that ChildClass.Dispose() is not called.

warm regards,

Danny

By on 8/6/2008 2:30 PM ()

You should override Dispose instead of reintroducing it's implementation. Or excplicitly call base's dispose.

By on 8/6/2008 10:26 PM ()

I was indeed wondering about the use of the "use" keyword in implicit constructions as mentioned by Danny Asher.

The reason was that I saw the issue in the control.fs file of the distribution in the the mailbox class, and was wondering if there was a way to avoid implementing the IDisposable interface...

Thanks for your help !

By on 8/7/2008 5:10 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper