Your workaround fixed the problem. Thanks very much!

For completeness, the modified code is below:
    
    
    import tables
    
    type AObj = object
        name: string
    
    proc `=destroy`(x: AObj) =
        echo "Destroying A named ", x.name
        `=destroy`(x.name)
    
    type BObj = object
        name: string
        tableField: Table[string, AObj]
    
    proc `=destroy`(x: BObj) =
        echo "Destroying B named ", x.name
        `=destroy`(x.name)
        `=destroy`(x.tableField.addr[])     # Workaround for lack of =destroy 
in Table
    
    proc newBObj(name: string): ref BObj =
        result = BObj.new()
        result.name = name
        result.tableField["A#1"] = AObj(name: "A#1")
    
    echo "Creating B#1"
    var bobj1 = newBObj("B#1")
    
    echo "Setting B#1 to NIL"
    bobj1 = nil
    
    echo "... Done"
    
    
    Run

The output, shortened for brevity:
    
    
    Creating B#1
    Destroying A named
        <...>
    Destroying A named
    Setting B#1 to NIL
    Destroying B named B#1
    Destroying A named
        <...>
    estroying A named
    Destroying A named A#1
    Destroying A named
        <...>
    Destroying A named
    ... Done
    
    
    Run

Reply via email to