example code free memory allocated for each thread