> Shouldn't context stay a ref object?

Are you familiar with GTK and cairo?

Well ref object without GC may be fine, but I think that is still work in 
progress for Araq, and I have to learn that then.

But destructors work already, as they are used for seqs and strings, and it is 
my feeling that value objects with destructors should work for the proxy 
objects fine. One problem is when we get objects back from gtk, for example 
gtk_get_child(gtk_table). For that we get a ref object currently, but its a 
plain widget, so we have to cast it to whatever it really is, maybe a button. 
It not nice currently. I think I can solve that with a generic get(), like 
getChild[Button](table) which gives us the Button widget or raises an 
exception, or maybe returns false when widget is not a Button.

But well, that explanations may make not much sense to you.

The concrete problem with ref objects and GC is caro drawing as in

[https://github.com/StefanSalewski/gintro/blob/master/examples/drawingarea.nim](https://github.com/StefanSalewski/gintro/blob/master/examples/drawingarea.nim)
    
    
    proc paint(this: PDA) =
      if this.surf != nil:
        cairosurfaceDestroy(this.surf.impl) # we may have to fix that later for 
automatically destroy
      this.surf = this.darea.window.createSimilarSurface(Content.color,
          this.darea.allocatedWidth, this.darea.allocatedHeight)
    let cr = newContext(this.surf)
    
    
    Run

Here we use temporary surface and context -- handling that with GC is 
problematic of course, as the proxy object is tiny, but the cairo surface is 
large, and that proc is called 60 times a second. So the GC may delay freeing 
for a long time, which may give us some 100 megabytes of temporary allocated 
mem for surfaces. Well we may do a GC_fullcollect for each proc call, but that 
is not what the GC is designed for.

I had the same issue with Ruby in 
[http://ssalewski.de/PetEd.html.en](http://ssalewski.de/PetEd.html.en) 
resulting in crashes.

I think value proxy objects with destructors should catch that well. And if we 
use them for cairo, we can use them for all gtk and can avoid the GC fully. I 
would guess that is what gtkmm does also.

For copy, isNil, == you are right of course, but I think we can define that 
well. 

Reply via email to