Channel-oriented memory management

Rework internal memory management routines so that memory can be managed (free(0'd) on a per-channel instead of a per-connection basis.