I was just thinking about how I can prevent a call of destroy from within a 
proc, because for callbacks we do not want destroy calls for parameters owned 
by GTK.

But it seems that this tests does not generate a destroy call for proc 
parameter at all?
    
    
    type
      O {.bycopy.} = object
        i: int
    
    proc new(o: var O) =
      echo "new called"
    
    proc `=destroy`*(s: var O) =
      echo "=destroy called"
    
    proc `=sink`*(a: var O; b: O) =
      echo "=sink called"
    
    proc createO: O =
      result.i = 7
    
    proc p(o: O) =
      echo "working with o"
      echo o.i
    
    proc main =
      var
        o: O = createO()
      p(o)
      echo o.i
    
    main()
    
    
    
    Run
    
    
    $ ./h
    =sink called
    working with o
    0
    0
    =destroy called
    
    
    
    Run

I have added the bycopy pragma, but that makes no difference. There is only one 
destroy call, and that is for the o var in main. When I add a local var of type 
O to proc p() we get another destroy call as expected. 

Reply via email to