Fix reference counting
Check whether reference counting is done correctly. This can also be tested to some extend in unit tests.
Edited by Frank Sauerburger
Check whether reference counting is done correctly. This can also be tested to some extend in unit tests.