Fix memory leak
Add performance counters (c++ only)