I frequently run into the situation that I want to share WebGL resources - especially textures - between multiple objects. For example, in the terain and imagery system, a single imagery texture is frequently shared among multiple terrain tiles. WebGL resources, as you probably know, should be freed explicitly rather than left to be managed by the garbage collector. So the best way I know to deal with this is by reference counting. Every time we add another reference to the object, we increment its reference count. When we remove a reference, we decrement the reference count. When the reference count goes to zero, we free the resource. Simple enough.
So my question is: should we add reference counting capability to all of our types that represent WebGL resources? It adds a little bit of cost in terms of object size and runtime cost (for managing the reference count), but I think it’s worth it to save the (common?) client that needs to count references the trouble of doing ad-hoc reference counting on these types. I’ve found myself doing that multiple times now.