**Example**
    
    
    type
      Foo = ref object of RootObj
        data: int
        parent: Foo
    
    proc `=destroy`(self: var type(Foo()[])) =
      echo "destroy foo ", self.data
      for i in self.fields: i.reset
    
    proc getParent(self: Foo): Foo = self.parent
    
    var foo1 = Foo(data: 1)
    var foo2 = Foo(data: 2, parent: foo1)
    
    foo2.getParent.data = 1
    
    # output
    destroy foo 2
    
    
    Run

**Possible Solution 1**
    
    
    proc getParent(self: Foo): lent Foo = self.parent
    
    # output
    destroy foo 2
    destroy foo 1
    
    
    Run

**Possible Solution 2**
    
    
    var foo = foo2.getParent
    foo.data = 1
    
    # output
    destroy foo 2
    destroy foo 1
    
    
    Run

To my understanding, lent type for ref object is meaningless, it shouldn't 
change the result for the code. 

Reply via email to