[WIP] memory leak

This is starts to look into fixing memory leaks as described in #21

The PR is still WIP because the leaks appear in different conditions and I still encounter some.

The core issue is that the Intel and Nvidia platforms only free memory iff every object belonging to a ??context?? has a ref count of zero.