On 07/02/2012, at 2:40 PM, Clark Gaebel wrote:

> Awesome. Thanks!
> 
> As a follow up question, how do I add a finalizer to a normal variable? 
> OpenGL returns an integer handle to your texture in graphics memory, and you 
> have to call deleteObjectNames on it. Is there any way to have this 
> automatically run once we lose all references to this variable (and all 
> copies)?

I don't know. I've only used ForeignPtrs with finalisers before [1].

One problem with these finalisers is that GHC provides no guarantees on when 
they will be run. It might be just before the program exits, instead of when 
the pointer actually becomes unreachable. Because texture memory is a scarce 
resource, I wouldn't want to rely on a finaliser to free it -- though I suppose 
this depends on what you're doing.

Ben.

[1] 
http://www.haskell.org/ghc/docs/latest/html/libraries/haskell2010-1.1.0.1/Foreign-ForeignPtr.html


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to