memory management improvements

- proper reference counting in driver
- unlock video memory before free