csyonghe / Spire

Other
174 stars 22 forks source link

Fixup for `typedef` change. #72

Closed tangent-vector closed 7 years ago

tangent-vector commented 7 years ago

The "canonical types" being created in that change weren't being cleaned up. Doing so isn't as trivial as making them use RefPtr because a type might be its own canonical type and we don't want to introduce self-reference. Similarly, issues can arise if we are a named wrapper around a canonical type (we can't free our canonical type either, because somebody else might reference is).

The fix here is simplistic and a bit silly. Part (1) is making ExpressionType use RefObject so that it has an internal refcount (so we can recover a RefPtr from a raw pointer, if we ever want to) and part (2) was storing a global (static) list of all expression types created as part of canonicalization so that we can free them.

All of this would go away if we used some kind of pool to allocate these types.