Bugfix/osx memory footprint

Patch for #672, ready for review and merge.