Application profiling

Fix memory leaks.